My Android application restarts after screensaver appears - android

Everytime after couple minutes of idle state, screensaver appears on my phone. It makes my Android application restart. Do you know how to overcome this? Of course, I know I could turn off the screensaver, but it's not the solution I am looking for.

What do you mean by restarts? What do you mean by screensaver? If I understood your question correctly you must check if you have this line in your AndroidManifest.xml:
android:configChanges="keyboardHidden|orientation"
This will prevent your activity from being restarted on runtime 'configuration changes'.

Related

Android: Make app not closeable (kiosk) under certain circumstances

I have a problem that I don't really know how to solve and also the threads here at SO haven't fully helped me.
Here's the issue: I want to have an android app that I can start whenever I want, and then, when I click on a button, I want the app to be somewhat "locked". By that I mean: after this button was pressed, the user is not able to close(see edit below) the app. Also, the app should immediately start after rebooting the device.
This lock can then be revoked by, say, entering a passcode, which makes the app run normally again.
So far I understand how to build kiosk applications. However, a kiosk application needs a particular manifest which will make it always a kiosk app, and not "on demand".
I'd greatly appreciate any hints and tips on this topic. Thank you so much!
EDIT: by "close" I really only mean completely turning the app off, not only going back to your home screen. Such that the app is always running in the background
You can programmatically lock and unlock the App in Android 5.0 http://developer.android.com/about/versions/android-5.0.html#ScreenPinning

Why when rotating the phone from portrait into landscape, does the app lose all data?

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.

Programmatically simulating Android OS killing my app [duplicate]

This question already has answers here:
How to simulate Android killing my process
(15 answers)
Closed 9 years ago.
My application behaves a certain incorrect way after it is killed by the OS while running in the background. In trying to debug this, I've had to basically wait for the OS to do this on every go around - this is very slow, so I was wondering if there was a way of programmatically telling the OS to kill my app.
I have tried android.os.Process.killProcess(android.os.Process.myPid()) and finish() but those don't seem to produce the same behavior as the natural way does.
Does anyone have any suggestions?
You could go on your phone to Settings | Developers Options and set 'Don't keep Activities' checkbox. I'm not sure about exact wording.
This way as soon as any your Activity is in background it immediately gets killed.
You can try setting on Don't Keep Activity feature inside Developer Options.
When you leave each Activity (Because you start another one), Android will kill it (When you are running on low Memory Android behaves this way). Setting this feature on, you will be forced to manage in the proper way the state of each Activity using onSaveInstanceState() and checking por savedInstanceState Bundle in your onCreate()
try the below process:
go to settings->developer options->check the "don't keep activities" checkbox.
Try to use the genymotion that is a excelent Android Emulator. It let you set the battery level and other configurations that can finish your application and do what you want.

Android application orientation change behavior

I'm done with developing an android application and in phase of testing it. I've tested it with the simulator and everything is working perfect, but when I deploy it on devices, some of them when you change the screen orientation the application screen starts to flicker.
Any clue where to start the problem investigation from?
When orientation changes from portrait to landscape or vice versa, onCreate gets called again, making the application to start from the beginning. Make sure you are handling it in manifest by declaring android:configChanges="keyboardHidden|orientation" infront of your class name or override onConfigChanged() function.
Please check Both Device version and Developing Application Versions are the same or not, and clear the application after install to the device and then run.

Android app gets stuck when I turn tablet - first timer

I'm first time developer for these types of devices, and UI in general, so I could be missing something basic and obvious.
Everything seems to work fine in the emulator, but I don't know how to simulate turning it.
So I tried running the app on my pandigital (white model - lowest of the low it seems), and each time I turn the Android, it freezes up. At least the UI freezes up, I believe the debug messages are still printing.
This is a home project, I don't have other devices to try it on.
Sorry for being so vague, it's an issue I have been a bit neglecting, trying to work on more interesting issues first, but it's an issue that is bothering me in the back of my mind.
Anyway, I have an Activity that starts up a thread, and creates a class which responds to various events, it implements: MainInterface and SurfaceHolder.Callback. Is there something else I should be handling? possibly?
Is there some specific call I get when the tablet is turned? I'd like to put a debug message in there.
My guess is that you state in your AndroidManifest.xml that this activity will handle rotation events itself (perhaps because you copied it from some project where the activity did do this), and that this statement is a lie, your activity actually makes no attempt to handle rotation.
If this is the case, a sound way to solve your problem is simply to remove the lying android:configChanges from your manifest.

Categories

Resources