I am narrowing down and explaining as simple as can,
main activity initiates an async task.
When orientation change onCreate() is recalled so Async is created once gain. so in onPreExecute() i lock my orientation and in onPostExecute() i release lock on orientation. By this way if Async task has started another instance of task will never get created.
another issue has started, in main activity itself findViewById() returns null when i randomly keep changing the screen orientation. Re-producing once in 5-6 tries.
how to go on this? any help
Does onCreate() get re-called after completion of method or main thread... or is it instantaneous as soon as orientation get changed
Thank you
---------------updated
<application
android:allowBackup="true"
android:icon="#drawable/ap_logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="agilepoint.android.mobilebpm.main.LoginActivity"
android:configChanges="orientation"
android:label="#string/app_name"
android:logo="#drawable/menu_button"
android:windowSoftInputMode="adjustPan|stateHidden"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
</intent-filter>
</activity>
</application>
Found my solution...
android:configChanges="orientation" does not work with fragments
if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the screenSize value in addition to the orientation value. That is, you must declare android:configChanges="orientation|screenSize".
Add android:configChanges="orientation" for that perticular activity in manifest.
Related
THIS QUESTION IS SOLVED, PROVIDING ANSWER FOR FUTURE SO VISITORS BELOW
Context :
I am developing a default phone app. Which handles action.DIAL and action.CALL from My application as well as it handles these both intents from other apps too.
What is problem :
If my CallActivity is running ( if any call is ongoing ) then -
When i again try to open my app, it is presenting me CallActivity only.
And because of this i am unable to make another call by opening my app.
What manifest.xml looks like :
<application
android:allowBackup="true"
android:directBootAware="true"
android:fullBackupContent="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.CALL_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<activity
android:name=".CallActivity"
android:label="#string/title_activity_call"
android:process=":CallManager"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter android:priority="800">
<action android:name="android.intent.action.ACTION_CALL" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
</application>
What i found when searched for the said problem :
How can I launch an independent activity to my application as well as the application of phone launches the activity to make calls?
https://stackoverflow.com/questions/9458300/how-to-create-an-android-activity-and-service-that-use-separate-processes
What are my efforts taken :
You can note i tried android:process=":CallManager" attribute in manifest for my CallActivity
Did that solved the issue :
Nope. I am still unable to open my MainActivity, whenever CallActivity is running. But is caused the problem that now my call is not getting ended as this is completely another process it is unable to reference other calls which remain there in older process.
ANSWER
Did android:process was correct :
No not at all in this case, as it is used when our app memory usage increases over particular limit android starts caching its services and resources in order to avoid it developers generally use android:process which allows them another heap memory available with same heap size.
** What was problem :**
It was related to task and its affinities
Both activities needed to be separated for tasks and their affinities
like :
<activity
android:name="com.example.ActivityA"
android:label="Activity A"
android:launchMode="singleInstance"
android:taskAffinity="com.example.AffinityA" >
</activity>
<activity
android:name="com.example.ActivityB"
android:label="Activity B"
android:launchMode="singleInstance"
android:taskAffinity="com.example.AffinityB" >
</activity>
I must thanks #JayWozz for his answer over SO https://stackoverflow.com/a/45488126/9810130 and must appreciate #gabe-sechan for his sincere help and efforts and for giving his value-able time for this thread.
I think you're basically asking for a new stack of activities. Try launching the intent with FLAG_ACTIVITY_NEW_DOCUMENT| FLAG_ACTIVITY_MULTIPLE_TASKS That will launch the activity as if its a new set of activities, with its own separate listing in the recent apps list. See the definiton of these flags at https://developer.android.com/reference/android/content/Intent
I have added android:configChanges in Manifest, when I change font size or turn off Wifi, the activity will be restarted automatically. Is there any way I can prevent this restarts ?
Thanks for the help.
<activity android:name="com.example.MainActivity" android:theme="#style/SkoletubeTheme"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|screenSize|smallestScreenSize"
android:launchMode="singleTask"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You have already caught the exception. It's happen for android:configChanges . Please remove unnecessary values from android:configChanges. Only keeps orientation .
I think your problem will be solved. Try this and let me know if it's acceptable or not.
My app seems to restart when it detects an orientation change. Well not really.
I only have portrait orientation enabled though.
In log cat I can see that my app is still doing calculations, but my progress dialog disappears.
What is going on?
In my manifest file this is my activity.
<activity
android:name=".xxxActivity"
android:label="#string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Is there a specific reason why you're listening for the orientation change with android:configChanges="orientation"?
If not, remove that and I suspect your problem will go away.
add this right after the super call
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Better to change configChanges to
android:configChanges="orientation|keyboardHidden"
I guess, that activity is restarted, because you forgot to add onConfigurationChanged(Configuration) method in your activity.
http://developer.android.com/reference/android/app/Activity.html#onConfigurationChanged(android.content.res.Configuration)
It can be empty but shold be in the activity.
Also android:screenOrientation="portrait" is not needed.
my android application crashes and shows force close when i tilt the mobile phone. is there any suggestions that i can remove such problem? By the way i am developing a LBS application which uses the google maps (MapView).
I have a splash screen and then shown a ListActivity as below :
<activity android:name=".Splash" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Home" android:label="#string/app_name" android:configChanges="orientation" android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="com.nepways.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
what is wrong with my declaration, the splash screen loads and list activity is also whown correctly but when i change the orientation the application is closed. Please help me.
When you change your orientation the activity is restarted
look at the logcat to see what exception causes your application to FC
You can change your manifest to disable activity restarting by customizing configChanges, if you stil have the problem override onConfigurationChanged() to fix what is generating this exception (like initialize something that may cause a nullpointer)
First of all as it is said the app is restarting (or as it is said in reference redrawing) each time when you change orientation.
To block it in your manifest file in activity you have to put this line which describes the activity orientation:
<activity android:name=".Splash"
android:label="#string/app_name"
android:screenOrientation="portrait">...
And about this buttons, or keymaps. Telling the truth Ive got thise warnings sometimes but it doesnt change anything in my app. So first change the orientation settings and then it should work correct.
If you want use other screen orientation remember to check here:
http://developer.android.com/guide/topics/manifest/activity-element.html
If you want to avoid restarting your activity on orientation change, you can put this in the activity in the manifest file:
android:configChanges="orientation"
Otherwise, we will need to see more code, and a stacktrace.
If I use this code in my Manifest file:
<activity android:name=".MyAct"
android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden"> //<-SEE THIS
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
As you can see I am declaring that the activity shall not be restarted when the screen rotation and keyboard visibility have been changed.
However, does this mean that the method onConfigurationChanged() will be called ONLY in case of these two events (in other cases the activity shall restart)?
Or it means that the activity does not restart even if only one attribute has been used?
I haven't been able to find this answer in the documentation.
Correct. It means that the activity does not restart even if only one attribute has been used. The onConfigurationChanged() method will be envoked if one of the attribute occur, i.e for those which are not specified, the activity will restart when they occur.