Reputation: 505
I am trying to make a simple project that could move the application to background by using
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK){
moveTaskToBack(true);
}
return super.onKeyDown(keyCode, event);
}
and now I am trying to bring the application to the front, displaying on the screen automatically even though user didn't reopen the application
For example, I set the timeout as 30 seconds, then I close the application (which is moved to background actually), after 30 seconds, the application will automatically move to front and shows text "Time Out". If I am playing games during time out, the game will pause and display the Time Out page, I tried to search for the solutions but the result is quite disappointing. the below are the codes I using now to bring the page to front, but it is only display in the app, unless user reopen the app then onli they can see the Time Out page otherwise they will not know
Intent intent = new Intent("com.lolcash.lol.PopOut");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
is there any other way to do that?
Upvotes: 0
Views: 1470
Reputation: 782
Try to create a service, this will run in background. When you want to bring the activity to front you can start it from the Service
.
Another solution would be to display a notification with a message, when the user will tap it you can take him to the app.
Upvotes: 1