0

Concern

People have been suggesting on SO that don't use System.exit for closing the app.

Problem

When user opens the app from history, and when the process of app is destroyed by the OS, and user tries to open the app from history, it crashes.

Solution, i tried

Added a check in base class, that checks if app process is killed, then call System.exit(0), this will restart the application, hence no crash will happen and everything will run smooth.

Questions

My app has background services, that sends me user lat/lng after specified time, will system.exit(0) effect that background service?

System.exit(0) just works fine for me, i tried calling finish(), but it causes crash, so the only solution for me is using system.exit(0)

It is not recommended approach for using System.exit(0) in android, right?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
dev90
  • 7,187
  • 15
  • 80
  • 153
  • why do you post both the question and the answer as a question? – Stultuske Jan 16 '18 at 13:15
  • 6
    "it crashes" -- fix the bug in your app. "so the only solution for me is using system.exit(0)" -- or you could fix the bug in your app. – CommonsWare Jan 16 '18 at 13:16
  • @CommonsWare : yes i will do that later, but for the quick fix i am using `system.exit(0)`, and i am concerned if this will have any impact ? – dev90 Jan 16 '18 at 14:21
  • @Stultuske , i have shared my findings, i still don;t have answer of this question; `consequences of system.exit(0)` – dev90 Jan 16 '18 at 14:25
  • 1
    *yes i will do that later* - just do it now – Tim Jan 16 '18 at 14:47
  • 1
    Maybe you should instead post about the crash with the logcat – OneCricketeer Jan 16 '18 at 14:48
  • @cricket_007 It is NPE ... https://stackoverflow.com/questions/48182709/how-to-pass-context-to-a-module-classes-without-using-static-context ... he is asking question about same story for 4 days ... obvious solution is to check if static data are initialiazed and if not(and "First Activity" is matadory) then clear the activitie's stack history and start "First Activity" again ... or if it is not matadory then use Contex which can be provided from current(not "First Activity") Activity ... but it need some knowladge about android's app lifecycle – Selvin Jan 16 '18 at 15:15

1 Answers1

0

I don't think the normal lifecycle events are run when you do System.exit(0). The process is just killed.

By using finish(), you let Android know that you want to destoy the Activity and let Android take the necessary steps.