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

All activities in my application require a user to be logged-in to view. Users can log out from almost any activity. This is a requirement of the application. At any point if the user logs-out, I want to send the user to the Login Activity. At this point I want this activity to be at the bottom of the history stack so that pressing the "back" button returns the user to Android's home screen.
More details: http://stackoverflow.com/questions/3007998/on-logout-clear-activity-history-stack-preventing-back-button-from-opening-l

Test Case #8


File ID: #3008684-3-cc


private static IntentFilter intentFilter = new IntentFilter();
public static void setReceiver(final Context context) {
    intentFilter.addAction("com.package.ACTION_LOGOUT");
    context.registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
            ((Activity)context).finish();
        }
    }, intentFilter);
}

  1. A nice solution, but instead of using a registering the Broadcast receiver as described in the code above, you should use a LocalBroadcastManager.getInstance(this).registerReceiver(...) and LocalBroadcastManager.getInstance(this).unregisterReceiver(..). Otherwiser your application can receive intents from any other application (security concern)
  2. Does this work if an activity somewhere in the stack was shut down by the OS to recover memory? Ie. will the system consider it really finished after the broadcast above is sent, and will not recreate it on hitting the back button?
  3. What if activity on backstack is killed by system (low-memory) and this activity will not receive broadcast. But this activity will stay on back stack record. Not sure if this is the most bullet proof solution.

Comments Quality
Accurate?:
Precise?:
Concise?:
Useful?: