3

My app seems okay. but when I try to clean the memory which is native on my Galaxy S4 when I open again the app seems all buggy and crash giving NullPointerException. The same happens when the app stays open for long periods of time.

enter image description here

Is there a way to permanently close my app when this kind of things happen?

I already close okay with

db.close();
finish();

just need to know when

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
rnascimento13
  • 75
  • 1
  • 7

1 Answers1

3

There are a few scenarios in which your activity is destroyed due to normal app behavior, such as when the user presses the Back button or your activity signals its own destruction by calling finish(). The system may also destroy your activity if it's currently stopped and hasn't been used in a long time or the foreground activity requires more resources so the system must shut down background processes to recover memory.

By default, the system uses the Bundle instance state to save information about each View object in your activity layout (such as the text value entered into an EditText object). So, if your activity instance is destroyed and recreated, the state of the layout is restored to its previous state with no code required by you. However, your activity might have more state information that you'd like to restore, such as member variables that track the user's progress in the activity.

u have to save those data in onSaveInstanceState(Bundle outState) and use onRestoreInstanceState(Bundle savedInstanceState)

enter image description here

for more info Visit here

http://developer.android.com/training/basics/activity-lifecycle/recreating.html

Community
  • 1
  • 1
Kaushik
  • 6,150
  • 5
  • 39
  • 54
  • Turns out the savedInstanceState i was assuming is not null only on screen orientation situations, i did not antecipate i would run not null! How can i diferenciate between orientation changes and other kinds of changes? – rnascimento13 Feb 22 '14 at 04:31
  • for orientation change u have to handle `onConfigChange()` – Kaushik Feb 22 '14 at 09:50