0

I want to run an application in background. I want to make an application when battery down to specific level I have to send sms to someone. If my phone is on standby or I am playing game and battery level reach 5% then I have to send sms. I want to Know how to run an application in background??

if (BtryLevelOrig==batteryLevel) {
        Toast.makeText(getApplicationContext(), "level", Toast.LENGTH_SHORT).show();
        SendSms();
    }
M.ArslanKhan
  • 3,640
  • 8
  • 34
  • 56
  • so... what is your question? – Jorge Alfaro Mar 24 '14 at 19:34
  • What are you actually asking here? How to register for a notification when the battery level hits a certain level? – Michelle Mar 24 '14 at 19:35
  • possible duplicate of [how to register broadcast receiver for low battery in android?](http://stackoverflow.com/questions/5513317/how-to-register-broadcast-receiver-for-low-battery-in-android) – Michelle Mar 24 '14 at 19:37
  • @Michelle actually I want to know how to run an application in background??? – M.ArslanKhan Mar 24 '14 at 19:44
  • You may have better luck using [an Android developer support site](http://www.andglobe.com) that is in a language that is more comfortable for you. – CommonsWare Mar 24 '14 at 19:56
  • @Tarikhelian Do you want your app to do anything other than perform an action (sending an SMS) when the battery is low? Because a broadcast receiver will start your service when it needs to (when the battery is low) without having to run it constantly in the background. – Michelle Mar 24 '14 at 20:03
  • @Michelle I got the solution below by Libin... i was Confused about the application that run in background. Its "Android service" that perform background task. Thanks – M.ArslanKhan Mar 24 '14 at 20:37
  • @CommonsWare.. I can understand English well but sometimes question confuse me about how to ask. Technically terms can understand everybody but if someone don't knows about Technical terms then question become Ambiguous. – M.ArslanKhan Mar 24 '14 at 20:43

1 Answers1

1

You have to use Android Service . If you have to show any user interaction notification, then you can also run your service as Foreground using startForeground

check this link to create your own background custom service. make sure onStartCommand return START_STICKY to run your service continuously .

http://developer.android.com/guide/components/services.html

Libin
  • 16,967
  • 7
  • 61
  • 83