0

If you rotate your phone while an Activity is in the middle of its completion is a new Activity created again due to change in its orientation?

Onik
  • 19,396
  • 14
  • 68
  • 91

2 Answers2

0

Yes, if you do not manage configuration then same activity will start again from the beginning. That mean in the middle of process in activty when you rotate the device then it will destroy the activty (onDestroy() method will call) and than it will repeat activity life cycle and it will call onCreate() method. if you want to manage configuration then use reference of this link. Activity restart on rotation Android

Vatsal Desai
  • 169
  • 4
  • if I have an AsyncTask instance connected to the activity, then does the AsyncTask(even if it's in middle of the work) instance gets destroyed if the corresponding activity gets destroyed? – Grounded Snippets Feb 03 '18 at 18:26
  • Yes, Async task and all the other instance that you declare in activity will destroy when activity destroy. – Vatsal Desai Feb 04 '18 at 10:27
  • _"Yes, Async task and all the other instance that you declare in activity will destroy when activity destroy"_ It's only true if AsyncTask finished its background task. Otherwise the Context (Activity) will be leaking preventing itself from being GC-ed ("destroyed"). – Onik Feb 04 '18 at 10:51
0

Yes.

The answer is simple. For different configurations, we need different resources and for getting different resources, we need to create a different instance of an activity.

Debdeep
  • 752
  • 10
  • 22