0

I have an app ,that log print something like this:

 GC_CONCURRENT freed 433k,7% free 7975K/8564K,paused 12ms+4ms, total 70ms

the app work fine if keep using it,but when lock screen the app have trouble.sometimes after screen lock it die,sometime after screen lock it delay 10 second to be back.I see the log message and find that the backstage service fine when the UI die.is that caused by the memory leak?from GC_CONCURRENT can see only 7% memory are free.I wonder where I have missed.

and the other problem is I use an subclass to exit activity.when I click the back button,I call this code:

public void exit() {
    Log.e(TAG, "exit in myapplication");
    for (Activity activity : activityList) {
        Log.e(TAG, activity.getLocalClassName()+ " finish");
        activity.finish();
    }
    System.exit(0);
}

but after the finish() done, onDestroy in activity not called.why? anyone help me will by highly appreciated.

PS: I know these are maybe two questions but it's OK to put in one ?

Xoangle
  • 405
  • 6
  • 11

1 Answers1

0

You should not be managing activities by yourself, the system is taking care of that. Additionally, you should not either kill the application, again, this goes against the developer guidelines.

That said, you problem certainly comes from the fact that you are keeping references to activities, which prevents the system from destroying them. Simply stick to the recommended way of doing things, Android is not Windows Phone or iOS, you don't kill applications but let the system decide when they need to be killed.

See for instance that article from Reto Meier, Android dev @ Google: When to Include an Exit Button in Android Apps (Hint: Never)

Vincent Mimoun-Prat
  • 28,208
  • 16
  • 81
  • 124