Issue when application is running in background - android

I am facing an absolutely abnormal problem in my android application.Scenario is like that:-
I have a main activity in which a button is placed named as SOS .On long press the button,another activity is launched in which a timer starts.
The timer is executed in a service so that it can be easily runs in background also. Now the timer is running and when i pressed the home button of the device the app goes in background.Till now its fine.Now the problem is that when I again launch the application by clicking the application icon.The timer is not visible.
The application starts again from scratch.but the timer is still running in the background.What I want that,the same screen should be reopened when the application is launched again that is Timer screen.Now this problem is not arises when I deploy the build from the eclipse.Everything is working fine in this case.
But when I deploy the build in the device after downloading from the mail account,the above problem arises.
Please help me to sort out this problem.

Hope you know the behavior of Android OS,
When your Activity is in background and OS need to free some memory it will kill your app and start it again when you need.
If everything is right in your logic then might be your app being terminated by OS.

Related

Cannot simulate process death

I am trying to simulate "Process Death" in my Android Studio and have done the following steps:
Changed Background process limit in emulator
Test app has Application class, MainActivity and Activity2 with just layout. Run the app and open Activity2.
Press home button and open more than 5 other apps.
Check attatch to debugger and no process exists.
Go to the emulator and open the app from recent app menu.
I expected I would see the Activity2 but the app starts thorugh normal process and I was able to the application class started and MainActivity only shown.
Am I missing something to reproduce process death? Quite confused with this.
Thanks in advance with your help.

Android: Bringing activity to front at end of timer and resume app

I found similar questions, but I can't seem to make any solution work for my scenario. I am new to development, so please bear with me.
In one of the activities in my app, there is a timer. I would like the following:
1) To have the timer continue to run in background even if user switches to other apps OR another screen within the app
2) To have only one such instance running from the app
3) Once the timer finishes, the app screen is back on top (similar to timer in the android stock clock app)

Launch android app after start and block other apps

I'm facing the following problem. I want to make an android device to run only my application. All other apps and phone feautes should not be available to a user.
The reason why I want to achieve this is simple: I want to destribute devices with preinstalled application to my client but I don't want to let them use all phone featues.
This could work this way: just after android boots my application is launched automatically and than somehow all other staff is blocked.
Do you have any suggestions how to achieve that? Is it possible? Do I need to root a device?
I hope you get my problem. Any advice you can give will be greatly appreciated.
This is a bit crude way. But see if it is of any help.
If you create your application as a launcher it will start on boot(using system broadcast BOOT_COMPLETED).
Then you need to override all the three android buttons Home, back and recent apps.
To override back button you just have to override the onBackPressed() method.
For home button you will start a service which will run in background. This service will check if your app is in foreground or not. if not then it will bring it in foreground. so when the user presses home the service will sense the foreground app isnt yours and launch it.
But for this switching back of your app android takes approx 3 to 5sec. In that period of time you can display a warning text which will block the user from stopping the service from settings.Also if you remove the activity animations then it will appear seamless.
For recent apps button the above trick will do. If the user tries to close the app using this button your background service will sense it and launch your app.
so its the background service that does all the trick. if you some how stop the service or uninstall the app you are through :p

Forced to stay only mine app and can not open another app

I am developing one android application. In that i need to do below task. Can anyone suggest me how to do below task?
I want to force to user to stay on mine app, he/she can not open
another app. Only mine app is visible to top?
How can i achieve this?
Any help is appreciated .
I had a requirement where I need my App to run in foreground always, so that no other App should be running other than my App. Also, I had created a menu inside my App to Exit the Service that I created that keeps my App running always in foreground (not in this demo).
I had created a demo for the same in my github named as MyBackgroundServiceDemo.
Notes:
My requirement was for Tablet only.
I disabled back button of my App.
When user presses home button it will stay to home for 5 seconds (which is default by Android).
My Service keeps running constantly to keep track of Apps that are running.
I had modified the Service according to my requirement later on to keep track of my requirements. Same way you also modify the Service to meet your requirement.

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.

Categories

Resources