i_raqz
i_raqz

Reputation: 2959

android application behaves indifferently when app is not used for a while

The app works fine when called afresh and used, but it doesn't behave well when user leaves it and the application is left running in the memory. Any attempt to switch back to it when it is running causes crash or black frozen screen. It might happen only when some time is left since it was opened first. To solve this, I am thinking of placing a Quit button and used this to kill the app

case MENU_QUIT: int pid = android.os.Process.myPid();
        System.out.println("Process id:"+pid);
        android.os.Process.killProcess(pid); 
        return true;

But I believe this is not the right way to solve the problem. Could somebody suggest a better idea.

Upvotes: 0

Views: 94

Answers (2)

segfaultomatic
segfaultomatic

Reputation: 57

Implement your activity's onPause method. Make it stop active processing threads, save what needs saving and stop processing (Task killers may kill you at any time so onPause might be where the app terminates).

Implement onResume in a way to reload whatever state the app was in and pick up where it left off.

Look at your code in onStart. Does it differ a lot from onResume? Perhaps that will narrow down where your state went awry. If onResume reinitializes something wrong or fails to reacquire some resource bad things can happen).

Upvotes: 0

Ted Hopp
Ted Hopp

Reputation: 234807

Those kinds of crashes and freezes can happen if you don't implement the process lifecycle callback methods correctly.

Upvotes: 3

Related Questions