Handle external interrupts while switching activities in an App - android

I Have developed an application which contains many activity.
I have noticed an issue while one activity starts another activity and meanwhile if we press camera button or get a call my application hangs and never recovers even after ending the call or closing the camera.
Basically what I want to know is how to handle external interrupts(alarms, calls, camera) so that my app resumes from where it had stopped.
I am replicating this issues on emulator as well as on LG Device.Can anyone give me some idea to how to handle onpause and onrsume function call in this case.
Thanks

Related

Activity loosing data after coming back from Camera Activity

I have an app where I should fill data on some edittexts or spinners. After that I have some buttons where I should take some pictures, sometimes there's 2 or 3 pictures. Im using a Camera Intent.
The problem is that SOMETIMES just in SOME PHONES, when the app comesback from Camera app it deletes all data filled on the views, and it deletes the pictures already taken. So it crush the activity.
I'm pretty sure its not the orientation, since IM using this on the manifest.
<activity
android:name=".MainActivity"
android:configChanges="screenLayout|orientation|screenSize">
I have nothing on the error log. One solution is when I delete data from Google Play Services or I unistall it and reinstall again. This fix the problem for sometime and then it happens again.
I dont know what else could it be. On the activity Im using Camera and Im accesing User location.
Camera app takes a lot of memory and on low-end devices with less memory system might kill your app to free some memory.
android:configChanges is more of a hack rather than a correct solution, it does not prevent a case as described above.
You should implement correctly activity life time cycle functions, by saving instance state in onSaveInstanceState and recreating it in onCreate. There is no other way around.
To test such cases, go to developer settings and disable applications in background. This way each time you will click on home button of your device, your app will be killed, and going back to it it will be recreated.

Do not close the camera just because another activity that I launched is in the foreground temporarily

I have a very stable application using the camera where I call camera.open() in onResume() and camera.release() in onDestroy() of my activity.
This is well and good, until I do some small task that requires another activity to be launched over the top of mine, such as getting the user to select a contact.
The problem is that as soon as my activity loses the foreground, onDestroy() is called which closes the camera. Then as soon as the user has selected the contact, we go back to my activity and the camera opens again.
I want to call the contacts app to select a contact without it closing the camera, but I also need to close the camera cleanly when my app is being legitimately shut down via back button, or home button, or something else.
This is a problem because the device is the samsung galaxy camera, and opening and closing the camera takes about 2 seconds for each phase, and also extends the lens out somewhat, which can be annoying if you are holding the device in your hand.
Any suggestions on how I can distinguish between a genuine closing of my app, and simply being placed in the background because of another activity that I called ?
Thanks.

Android App Launcher strange behaviour

hi guys i am finding the strange behaviour in android while launching the Application. Let me explain the senerio. I am launching my application from android's launcher page and my application starts and runs fine and after few minute i press home button and go to android home page and then go to launcher page and again select my application and it is starting it again from first but it should have resumed from the last place where i left. And when i press back button on the launch screen of second instance of my app i am able to go back to the last page where i have left. I am more confused about what was happening and it too happens sometimes only not every time. Hope you people could help me sort this problem, Hoping for better responses. Thanks in Advance.
Edit #1:
It is not happening in all the device it happens only with Samsung and Sony but works fine with LG and HTC.
To keep an activity running in the background is not in your hand. When you press the home button, your current activity goes to the background and can be killed (onDestroy() will be called) at any time depending on the need for memory of the other applications you launch.
The more apps you launch, the more chances of killing your background app is.
The behavior may be device specific - try saving your game settings in a persisted location within the 'onPause()' function, and retrieving it on 'onResume()'. Then it doesn't matter if a new activity gets launched or the old one gets called.

How to Resume Previous running application from An Application in Android?

Give me a little guidance:
as My Application is running with Broadcast Receiver and when ever my application in Background and any incoming event comes it triggers the my Application.
Now we want as We are listening or playing some video file or browsing on Android Phone
and with incoming event occur and my application launch(already running in Background),
If i will ignore the event , we want to go back previous running task (Like browsing, playing
video file application), How we can achieve?
Now I am using The store the running application package and Activity info before triggering the Event , and after finishing using this info we resuming the Activity and
It working fine but Only with Gallery Application Playing of Vedio file is not fine , It Crashes the Application and relaunch the Gallery App.
Please give me some Valuable points to make it up?
On calling finish, Previous application resume(Playing of Media file) but when next time
on getting broadcast intent and try to launch the Activity , The Activity is not launching
and application itself crashing.
After a long back I got solution of my problem and we need only use to this api
moveTaskToBack(true);
and automatically resumes the previous running task(like browser, media application or any thing)
Have you tried to start you activity by
startActivityForResult(Intent intent)
When you call finish() in the Activity you should return the the previous one, I am not sure if this will function over between Activity running in different applications. Give it a try :D

Open the same app instance

I have a simple, one Activity application.
The problem is that, if i press the BACK button, the application is minimized, but if i try to launch it again, another instance is started.
I know this because my app has plays a sound stream even if is minimized.
How can i maximize the already running instance when trying to launch it ?
I've tried with the code below, but is not working.
android:launchMode="singleInstance"
Android handles this for you. What is probably happening is you're replicating your objects in onCreate thus the "appearance" of 2 activities via a 2nd sound stream.
I don't know what is the C button ? If it is the "back key" so your application is unload from the system, when you start it again, it opens a new instance.
If you press the 'middle key', normally there is only 3 keys on a Android phone, your application is just paused and put in the background, and when you launch it again, the sytem just put your running application from the background to the foreground. No new instance is opened. There are the methods onPause() and onResume() which are triggered in this case.
Hope it can answer to your question

Categories

Resources