0

So my Application has an Activity A and few other Activities B,C,D etc, all of which opens on different clicks from Activity A. My requirement is to show a "Enter Pin" DialogBox every time app is opened from outside like (starting app first time, unlocking screen, resuming app after it was paused and other apps were used).

But Dialogbox should not show up when i open and close other Activities (B,C,D etc).

But in both cases, onPause->onStop->onRestart->onResume is called. So how should i distinguish that whether the user has gone outside the app or not and where should i place my dialog.show()

1 Answers1

0

In Activity A do like this,

@override
onCreate(){
 SharedPreferences.Editor editor = getSharedPreferences(PREFS_NAME, MODE_PRIVATE).edit();
  editor.putBoolean("isRunning", true);
  editor.commit();
}

@override
onStop(){
  SharedPreferences.Editor editor = getSharedPreferences(PREFS_NAME, MODE_PRIVATE).edit();
  editor.putBoolean("isRunning", false);
  editor.commit();
}

and in onResume() check the pref and if true then show your dialog.

@override
onResume(){

SharedPreferences pref = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
if(pref.getBoolean("isRunning",false)){
    //Show your dialog here
 }

}

NOTE : I apologize It's directly written in editor, I'll edit this after being with IDE, But use this logic.

Shree Krishna
  • 8,474
  • 6
  • 40
  • 68
  • sorry to say, but this is not the solution, i found the solution here [link](http://www.mjbshaw.com/2012/12/determining-if-your-android-application.html), but thanks for your time. – user3024990 May 18 '16 at 07:11
  • @user3024990 Its ok... But have some knowledge. Leave it as it is.. Glad to hear that you found solution. – Shree Krishna May 18 '16 at 07:13