1

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.

Deepak Sharma
  • 4,999
  • 5
  • 51
  • 61
  • 1
    timer task runs a different thread (other than the ui thread). So why do you need a service for your timer? – Raghunandan Sep 13 '13 at 09:56
  • Hi Raghu!! I have to use service because i have to do several task in my application.Please try to answer my problem state above.. – Deepak Sharma Sep 13 '13 at 10:41
  • so if you want to to several tasks what is the need for a service to be used with timer. Pls wait for others to answer. – Raghunandan Sep 13 '13 at 10:42

1 Answers1

1

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.

Pankaj
  • 1,242
  • 1
  • 9
  • 21
  • But Why the app is not killed by OS when it is deployed through eclipse? – Deepak Sharma Sep 13 '13 at 12:18
  • No its not linked with from where you have installed it, its arbitrary,completely depends on OS will. But you should check your logic, Can you explain what you are doing to show time in your activity and how you are preserving it? – Pankaj Sep 13 '13 at 12:25
  • Thanks a lot bro..Now when i uninstall the several applications on my android device,now the OS did'nt killed the my app.. :) – Deepak Sharma Sep 13 '13 at 12:32
  • But this is not right solution for you to just free some memory, You should consider this scenario in phones and build your app. So even if your app is killed, you should not loose your timer. – Pankaj Sep 13 '13 at 12:36
  • Is there any procedure to restrict the user to download the app. I mean to say if memory is not sufficient user cant install the app.. – Deepak Sharma Sep 13 '13 at 12:39
  • But even now i am not understanding that why the application is running when I deployed it through eclipse even the memory is full. – Deepak Sharma Sep 13 '13 at 12:47
  • No its not Internal or external memory issue, Its related to RAM.If RAM need to be cleaned then android has its priority to kill apps. Now you need to think in a direction, How can you preserve your timer even when app is killed.I think this is your solution. – Pankaj Sep 13 '13 at 12:47
  • ACtually timer not stops.It still running even when the application is killed because timer is running in service.But the issue is that when i pressed the SOS button again the timer seems to be running in background shows the correct time. Splash-->Main activity-->Timer activity--> Home button. launch app icon--> Splash--> Main activity-->Timer activity and timer stilll runs.. – Deepak Sharma Sep 13 '13 at 12:55
  • @DeepakSharma so the problem is that you are coming back to the wrong activity? Do you want to come back to Timer activity, and not Main activity? – Richard Le Mesurier Sep 13 '13 at 13:02
  • @RichardLeMesurier Yes friend..You r right.I have to come back to Timer activity again when the app icon click. – Deepak Sharma Sep 13 '13 at 13:07
  • @RichardLeMesurier But friend my code is working fine when i deploy my app through eclipse and the problem occur when the app is installed after downloading it through mail. – Deepak Sharma Sep 13 '13 at 13:21