Question

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?

Was it helpful?

Solution

Add this to your manifest under <activity>:

android:configChanges="keyboardHidden|orientation|screenSize"

OTHER TIPS

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" />

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top