0

I have a activity. I have a process and this is very long. I changed the screen orientation (portrait to landscape), they process is start again... I want to disable onCreate() on change screen orientation.

How make I this?

Cœur
  • 37,241
  • 25
  • 195
  • 267

3 Answers3

10

Add this to your manifest under <activity>:

android:configChanges="keyboardHidden|orientation|screenSize"
TronicZomB
  • 8,667
  • 7
  • 35
  • 50
1

I just added this on my activity

android:configChanges="keyboardHidden|orientation|screenSize"

Like this

<activity
   android:name=".MainActivity"
   android:configChanges="keyboardHidden|orientation|screenSize"
   android:label="@string/myBoards"
   android:theme="@style/AppTheme.NoActionBar" />
0

Am I right assuming that you start an AsyncTask?

Please, read Is AsyncTask really conceptually flawed or am I just missing something?

In general, you should save the Activity state in onSaveInstanceState(Bundle outState) and restore in onCreate(Bundle savedInstanceState).

There are things that cannot be packed into a bundle, for example, an AsyncTask; you may pass such things via onRetainNonConfigurationInstance().

And, of course, there still are static variables and member fields of the Application object.

Community
  • 1
  • 1
18446744073709551615
  • 16,368
  • 4
  • 94
  • 127