Battery Watch / monitoring application Android
<p>I'm working on an application to display the battery status of then phone/tablet. I have it running and working as it is, but somehow the application is 'killed' when the screen is turned off.</p>

<p>The strange thing is though that is is killed on my LG phone, but not on my Galaxy Tab when the screen is off/locked.</p>

<p>The source code is as following:</p>

<pre><code>public class BatteryLevelActivity extends Activity {
    private TextView batterLevel;
    CharSequence tickerText = "No need to charge at the moment";

public void onCreate(Bundle SavedInstanceState) {
    super.onCreate(SavedInstanceState);
    setContentView(R.layout.main);
    this.registerReceiver(this.mBatInfoReceiver, new IntentFilter(
            Intent.ACTION_BATTERY_CHANGED));
    batterLevel = (TextView) findViewById(R.id.batteryLevel);
};

private void notif(int level) {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

    int icon;

    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);

    Context context = getApplicationContext();
    CharSequence contentTitle = "BatteryWatch";
    CharSequence contentText = "Remaining charge level is " + level + "%";
    Intent notificationIntent = new Intent();
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            notificationIntent, 0);

    notification.setLatestEventInfo(context, contentTitle, contentText,
            contentIntent);

    notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;

    final int HELLO_ID = 1;

    mNotificationManager.notify(HELLO_ID, notification);

}

private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context arg0, Intent intent) {
        int level = intent.getIntExtra("level", 0);
        batterLevel.setText("Battery level is at " + level + "%\n\n"
                + tickerText);
        notif(level);
        tickerText = "";

    }
};
</code></pre>

<p>}</p>

<p>Somehow I think that I should have a method that is called something like 'onScreenOff' or maybe 'onScreenOn' and then the application could be reloaded, but I'm open to suggestions as to how to keeo it running when the screen is off/locked.</p>

<p>Thanks in advance</p>
