Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old December 31st, 2012, 02:36 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Dec 2012
Posts: 3
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Prevent Android os kill process(want app continuously running)

Hello Friend,

I am developing chatting app in which i have to run my app continuously in background also. but unfortunately sometime my app kill by Android OS. and i have to relogin. Is there any way to run my app continuously in background. Some App is available on Google play which is running in background.

Please help me to run my app continuously .
Thanks in Advance

amitsharma_ujj is offline  
Reply With Quote
sponsored links
Old January 1st, 2013, 07:15 PM   #2 (permalink)
not really so scary
 
scary alien's Avatar
 
Join Date: Mar 2010
Location: Indy
Posts: 16,615
 
Device(s): LG Nexus 5, Samsung Galaxy Nexus, Asus Nexus 7, Moto Droid X, HTC Droid Eris
Carrier: T-Mobile

Thanks: 30,624
Thanked 14,088 Times in 6,881 Posts
Default

Welcome to the AndroidForums, amitsharma_ujj .

I'm not sure you'll be able to...my experience is that Android may kill a background process at any time.

I have an app that has a background service and all I could do was try to gracefully recover from the termination.

There may indeed be methods that I'm not aware of, but short of having the app in the foreground, I'm afraid Android might keep killing your background process.

Maybe someone else with other thoughts or information will chime in.

Anyway, thanks for signing-up with us here at AF.
scary alien is online now  
Reply With Quote
Old January 3rd, 2013, 05:50 AM   #3 (permalink)
Junior Member
 
Join Date: May 2012
Posts: 27
 
Device(s): Nexus 7 (Android 4.2.1), Samsung Galaxy Mini (Android 2.3.6)
Carrier: Not Provided

Thanks: 1
Thanked 2 Times in 2 Posts
Default

You can consider using startForeground in your service. As the docu says:

Quote:
A started service can use the startForeground(int, Notification) API to put the service in a foreground state, where the system considers it to be something the user is actively aware of and thus not a candidate for killing when low on memory
The Service will still run in background with an icon in notification area.
myrecek is offline  
Reply With Quote
The Following User Says Thank You to myrecek For This Useful Post:
scary alien (January 3rd, 2013)
Old January 9th, 2013, 11:34 PM   #4 (permalink)
New Member
Thread Author (OP)
 
Join Date: Dec 2012
Posts: 3
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank for your reply...

can i have any reference startForeground Services ? i did goggle but not get the exact example.
amitsharma_ujj is offline  
Reply With Quote
Old January 10th, 2013, 03:28 AM   #5 (permalink)
Junior Member
 
Join Date: May 2012
Posts: 27
 
Device(s): Nexus 7 (Android 4.2.1), Samsung Galaxy Mini (Android 2.3.6)
Carrier: Not Provided

Thanks: 1
Thanked 2 Times in 2 Posts
Default

A nice code snippet can be found in Running a Service in the Foreground | Android Developers

You simply create a Service and add the startForeground call from that link into the onStartCommand method or anywhere you want.
myrecek is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:33 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.