Activity lifecycle – onCreate called on every re-orientation

android:configChanges=”keyboardHidden|orientation|screenSize” Caution: Beginning with Android 3.2 (API level 13), the “screen size” also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the … Read more

Why does calling getWidth() on a View in onResume() return 0?

A view still hasn’t been drawn when onResume() is called, so its width and height are 0. You can “catch” when its size changes using OnGlobalLayoutListener(): yourView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { // Removing layout listener to avoid multiple calls if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { yourView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { yourView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } populateData(); } }); … Read more

On logout, clear Activity history stack, preventing “back” button from opening logged-in-only Activities

I can suggest you another approach IMHO more robust. Basically you need to broadcast a logout message to all your Activities needing to stay under a logged-in status. So you can use the sendBroadcast and install a BroadcastReceiver in all your Actvities. Something like this: /** on your logout method:**/ Intent broadcastIntent = new Intent(); … Read more

What is Activity.finish() method doing exactly?

When calling finish() on an activity, the method onDestroy() is executed. This method can do things like: Dismiss any dialogs the activity was managing. Close any cursors the activity was managing. Close any open search dialog Also, onDestroy() isn’t a destructor. It doesn’t actually destroy the object. It’s just a method that’s called based on … Read more