I ran into the same problem and solved it by creating basic activity:
public class mActivity extends Activity{ public static final String TAG = "mActivity"; public static int activities_num = 0; @Override protected void onStop() { super.onStop(); activities_num--; if(activities_num == 0){ Log.e(TAG,"user not longer in the application"); } } @Override protected void onStart() { super.onStart(); activities_num++; } }
all other actions in my application are inherited. When activity is no longer displayed than onStop is called. when activity_num == 0, than all actions are not visible (this means that the user closes the application or transfers it to the background). When the user starts the application (or restarts it from the background), onStart will be called (onStart is called when activity is visible) and activity_num> 0. hopes this helps ...
source share