2

When my activity is destroyed by OS because of memory (for example when a phone call is interrupting it), then when my activity tries to start again, it doesn't come back to any expected call back except onDestroy(), how can I restore my activity again.

Note: - it doesn't go back to neither onCreate() nor onRestoreInstanceState(). - my activity contains a thread.

Edit: isFinishing() returns false at onPause() (before interruption) and it returns true at onDestroy() when come back again (after interruption is gone).

Alaa Eldin
  • 2,178
  • 4
  • 21
  • 24

2 Answers2

2

You should override the onPause() and the onResume() methods.

When a phonecall or an other event interrupts the execution of you activity, the onPause() is called.

then, when your activity goes on again the onResume will be executed.

  • I already did that, but it doesn't come back to onResume() so I cann't figure out how can I restore my activity. – Alaa Eldin Jul 03 '12 at 11:50
  • Thanks Thanos for your help, but as I said, it doesn't go to onRsume() after come back, it just goes to onDestroy(). – Alaa Eldin Jul 03 '12 at 11:54
  • yes, to be honest the onRestoreInstanceState() is the safest way to go... I can't think why is not executed! – Thanos Karpouzis Jul 03 '12 at 11:55
  • Unless if you haven't override the onSaveInstanceState(), maybe then you have a null state and that why is not executed – Thanos Karpouzis Jul 03 '12 at 11:57
  • no Thanos, I have overrided it ! anyway, it's mentioned at the life cycle in android website [link](http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle), but it should go to onCreate() after onDestroy(), but it doesn't !!! – Alaa Eldin Jul 03 '12 at 12:01
  • Well actually that connection between onDestroy() and onCreate() is not clear, you can see it also on the diagram. This link may be helpful http://stackoverflow.com/a/2441702/1340659 – Thanos Karpouzis Jul 03 '12 at 12:05
0

My program needs only to set "No History" option of my activity to "false"

  • at Manifest, Application, Application nodes, then select my activity-

after that I found it doesn't call onDestroy() when try to come back again to my activity, it calls onResume() as expected. and also set "config changes" to "orientation".

Alaa Eldin
  • 2,178
  • 4
  • 21
  • 24