Skip to content Skip to sidebar Skip to footer

Backbutton Quit The Application

I'm experiencing a trouble on my app, my backButton quit the application. My application is a SyncService, everything seems to be great in the Manifest, i check for one day with n

Solution 1:

Did you tried overriding onBackPressed ?

@OverridepublicvoidonBackPressed() {
       return;
}

Solution 2:

if you press back button while on the "main" activity (the first one you launched aka the bottom of your activity stack) the OS understand this as "the user is done and won't be back anytime soon" opposed as "home" button which is understood as "maybe the user wants to check something else before resuming the app"

So, if you DO NOT want your app to "terminate" (an android app terminates only when the OS kills it, otherwise it will lurk in memory until recalled) you need to override the back button pressed callback

publicvoidonBackPressed()

which the api doc describes as:

"Called when the activity has detected the user's press of the back key. The default implementation simply finishes the current activity, but you can override this to do whatever you want."

You might just ignore the event and absorb it like timo schloesser suggested or you can do whatever is most appropriated (like, launching another activity or killing services before leaving the screen)

EDIT: you might also want to check the "moveTaskToBack" method inherited from Activity class. I have never used it but it might be useful to your problem.

Post a Comment for "Backbutton Quit The Application"