0

To exit an app programatically in Android (for instance, if the user presses an exit button), I use:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

However, the CATEGORY_HOME intent category is not supported when porting Android apps for Playbook or Blackberry 10. What should I use instead?

Michael Donohue
  • 11,776
  • 5
  • 31
  • 44
1''
  • 26,823
  • 32
  • 143
  • 200

1 Answers1

1

I think your "exit an app code" for your Android app is quite the opposite of exiting the app: You start a new activity for the home screen instead of finishing "your own" activity.

You should instead finish your activity like this (and consider if that applies to more than one activity on your stack):

myAppView.finish()

This would also "quit" your application on bb10 - which means, it will be minimized and shown as an active frame until you tip on the X to close it.
As well, it would be a good idea to decide if you should clear outstanding notifications at this time (for my app, this makes sense...)

Schlangi
  • 1,135
  • 1
  • 9
  • 19
  • It's actually more complicated than this to finish all the activities in an app (see [http://stackoverflow.com/a/10407669/1397061]). My impression is that `finish()` will not close the app if there are any previous activities on the stack. My intention is just to clear the app from the screen anyways, since that's what the user sees. Thanks for pointing out that this doesn't really even happen on Blackberry, unlike on Android. – 1'' Apr 22 '13 at 15:39
  • Ah, now I understand your desire. But clearing the app from screen in Android is of cause not clearing it from stack, so if you long press your home button on Android device just after "exiting", your app will remain on top of the stack (or, in this case, on top of the list). This is namely the same as sitting on top of the active frames on the BlackBerry device. It is possible to really exit a BlackBerry native app, so maybe there is a way of invoking that from within an Android app for the BlackBerry, but we keep in mind that this is for sure another behavior... ;) – Schlangi Apr 23 '13 at 06:48
  • How do you "really exit" (as in, clear from memory) a BlackBerry app? – 1'' Apr 23 '13 at 14:50
  • See https://developer.blackberry.com/native/documentation/bb10/com.qnx.doc.native_sdk.devguide/com.qnx.doc.native_sdk.devguide/topic/c_appfund_applifecycle.html to find out about the lifecycle of a native BB10 app. You can for example register for the event thumbnail() and place code in the handler that calls "app.quit()" you provide. Because we are talking about native apps, this can be done with different means, here is an example how to implement an exit button with QML/Cascades: http://supportforums.blackberry.com/t5/Cascades-Development/Button-Exit/td-p/1945807 – Schlangi Apr 23 '13 at 15:25