i got this problem in some device, mostly china rom, problem is when plugged-in/out, the onDestroy called, then onCreate called -> activity restart, i tried to find anything of code that relate to this problem but not working.
Can anyone help me know the problem? Thanks
more update:
Here is the sample of one screen
<activity
android:name=".Screen.ChatScreen"
android:configChanges="orientation|screenSize"
android:theme="#style/AppTheme.AppBarOverlay"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
i tested then all screen restarted, not only one, only some specific android device. Samsung work normal
Related
I've made my app portrait-only and it works successfully, however there seems to be a cache. I can only have this kind of orientation:
[
But I can't rotate it 180°, it just shows like this:
But if I leave the app, the screen rotates. So the problem is, it seems that the app is being set to one-way portrait, is there a way to fix it? Here's how I'm setting portrait-only in each activity:
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"
Is there an option to fix this?
Try using this instead...
android:screenOrientation="sensorPortrait"
If this doesn't work let me know!
Edit
So people see this, it only works with API 9+ as #AbAppletic said in the comments below.
I have started developing on Google glass but i found something very weird. Activity ends when Google glass goes to sleep? Can anyone help me on how can i stop the glass from killing the activity.
I was having a very similar issue. I also found a related question here: https://stackoverflow.com/questions/31318952
As noted in the comments by the poster, adding the immersive property to my AndroidManifest.xml fixed the issue and the Glass now always wakes up to my Activity.
<activity
android:name="com.my.app.ActivityName"
android:immersive="true">
</activity>
I'm trying to create an app in Android, using Eclipse ADT and I use a HTC phone. Here's the problem: after running the app on the phone from Eclipse, I add elements to my ListView and everything is fine, BUT when I turn the device in landscape mode the hole app seems like it restart, there's no more records inside. It's like new. Any ideas why and how I can solve this problem? Please don't tell me to deactivate the screen rotate option from phone settings.
This is the way android handles orientation changes. It reloads your whole activity. The normal way to handle this situation is to save the state of your activity in onPause() and then retrieve it back in onCreate().
Here is more information on the android activity lifecycle:
http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle
EDIT:
You should implement onPause() anyway, because it will also be called if the phone rings in the middle of running your activity. In this case, when the user comes back from the call your activity will possibly be reloaded from scratch again and the user will lose their state.
There is a similar question here.
Basically you application is restarted. You can either force your application to portrait or follow the steps here to find out how to handle it properly.
I made answer over here about this sort of thing.
Please don't tell me to deactivate the screen rotate option from phone settings.
I'm not sure if you meant the following, but here's a solution:
Add android:configChanges="orientation|screenSize" to your <activity tag, which is in your AndroidManifest.xml, like so:
<activity
android:name="activity_name"
android:label="#string/app_name"
android:configChanges="orientation|screenSize" />
This will prevent the activity from being destroyed when the orientation is changed, like it usually would. There are other ways to fix this as well. Please leave a comment if this is not your desired solution. I can make up another.
I'm developing an Android application in which I need support a USB keyboard. I haven't developed something to explicitly support the USB keyboard because I thought that every application can use a USB keyboard.
The problem is that when I'm trying to connect or disconnect a USB keyboard, my application crashes without an error trace from the application.
My device is a Lenovo with Android 4.1 installed. What can I do to resolve this problem?
An Activity configuration change occurs when the external keyboard is attached.
To resolve the crash, add the following element to the AndroidManifest.xml for all activities:
android:configChanges="orientation|keyboard|keyboardHidden"
Per the documentation, android:configChanges:
Lists configuration changes that the activity will handle itself. When
a configuration change occurs at runtime, the activity is shut down
and restarted by default, but declaring a configuration with this
attribute will prevent the activity from being restarted. Instead, the
activity remains running and its onConfigurationChanged() method is
called.
For me, adding "orientation|keyboard|keyboardHidden" to configChanges would still call onDestroy and onCreate of the activity. After a long research I found this article:
https://developer.samsung.com/sdp/blog/en-us/2017/12/07/samsung-dex-lifecycle-on-switching-between-mobile-and-samsung-dex-mode
Basically, if you use Lenovo's productivity mode or Samsung DeX, it would recreate the app nonetheless, so it's necessary to add all of these if you want for the app to not recreate itself when you add a physical keyboard.:
<activity android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|uiMode|density">
Also, add this for Samsung DeX inside your AndroidManifest:
<meta-data
android:name="com.samsung.android.keepalive.density"
android:value="true" />
I have an app where all activities have the orientation overritten to be portrait.
This is what a random activity declaration looks like on the Manifest:
<activity
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name"
android:name=".activities.LeaderboardActivity"
android:screenOrientation="portrait" >
</activity>
There's nothing else changed for that matter on the LeaderboardActivity.java.
That code runs just fine on my phone, but when I loaded up the emulator to get some screen shots, it keeps sending me the following error:
"The application Android keyboard (process com.android.inputmethod.latin) has stopped unexpectedly. Please try again"
When I click "Force close", nothing happens, the app keeps running but the error pops up again in less than 10sec, making it impossible to do anything.
Has someone else experienced that kind of problem before?
And it's not a specific problem with my emulator, because all members of my team are getting the same error on their pcs, but not on their phones.
EDIT:
My friend told me he encountered this same problem, and resolved it by opening the AVD manually before starting the app, and only call the app when it's fully loaded. I still haven't tried that, I'll update this when I test this method.
Why are you using android:configChanges="orientation|keyboardHidden" since you are forcing android to stay on portrait orientation? Maybe that's the problem.. did you tried to get it off?