I’m starting a new category on my blog — Dev Diary, to document some of the errors that I encounter and what I did to fix them. I’m doing this in hopes of helping developers (including my future self!) as they work with code (and to get more blog visits! LOL). It’s nice to save […]
Android Development
Android Kotlin: ‘getter for position int’ is deprecated. deprecated in java
Today I encountered a deprecation warning as I’m coding the app: ‘getter for position int’ is deprecated. deprecated in java And I was like, whoa, this wasn’t deprecated a couple of months back when I last touched Android code… this is how long I’ve missed out! 😂😂😂 I haven’t touched any app code for a […]
Android Kotlin: “overrides nothing” error appears on instantiateItem() function of PagerAdapter
I just began learning Kotlin for work and one of the first errors I encountered is “overrides nothing” pointing at the overrides of the function instantiateItem() for my PagerAdapter The function/method signature was like this: override fun instantiateItem(parent: ViewGroup?, position: Int): Any { To fix the error, I simply removed the question mark from the […]
Android: Facebook SDK “Invalid Key Hash” on Ubuntu
I kept getting a different Facebook key hash from the one being actually generated by my debug app when it runs. Turns out I’ve been entering the wrong keystore password. To get your key hash for Facebook SDK on Ubuntu, run the following command:
1 |
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64 |
In case you don’t have the keytool program yet, you’ll […]
Android: SharedPreferences not accessible from SyncAdapter
When I was trying to access a SharedPreferences value from my Android app’s SyncAdapter, I kept on receiving an old value that was saved to the key. Quick solution to inaccessible SharedPreferences from SyncAdapter A quick solution (which may be a short-term one) I tried was to remove android:process=”:sync” from the following code:
1 2 3 4 |
<service android:name=".service.SyncService" android:exported="true" android:process=":sync"> |
But […]
Android app dev: Intent extras set in onBackPressed() misssing when back to onActivityResult()
It’s funny how we spent about an hour trying to figure out why the Intent extras that we’re setting are not being sent back to onActivityResult(). If we only knew that the solution was as simple as moving one line of code. The call to super.onBackPressed() should be placed after setting Intent extras and after […]
Android app dev: Missing import org.apache.commons.lang3.text.WordUtils;
I use a few instances of WordUtils.capitalizeFully() on an Android app that I’ve been working on. And there are times when the import org.apache.commons.lang3.text.WordUtils; breaks, sometimes after merging with some of my git branches. To fix this, what I do is open app/build.gradle and add the following line under dependencies:
1 |
compile 'org.apache.commons:commons-lang3:3.4' |
Hope this saves somebody […]
Something to avoid when using Android RecyclerView
When using Android’s RecyclerView, don’t use the same inflated XML layout file for items you intend to shuffle on the fly! Their contents will overlap. -CK
Android RecyclerView notifyItemChanged() IllegalStateException “Cannot call this method while RecyclerView is computing a layout or scrolling”
If your Android app is crashing with error IllegalStateException “Cannot call this method while RecyclerView is computing a layout or scrolling”, you may try placing your notifyitemchanged inside a Runnable. Assuming you have a call to notifyItemChanged() inside onBindViewHolder() that is making your app crash with IllegalStateException, you may try something like this:
1 2 3 4 5 6 7 8 9 |
myRecyclerView.post(new Runnable() { @Override public void run() { myArrayList.remove(position); myArrayList.add(something); recyclerViewMainScreenHeader.getAdapter().<code>notifyItemChanged</code>(); } }); |
Simple SMS Reader app in Android using BroadcastReceiver class
Before I began coding Android apps, I was amazed how verification processes go like this: The Android app tells you they’ll send you an SMS containing verification code, and that you need to enter such code into a text field on the Android app. But when you receive the SMS, the verification code appears on […]