Is there a way to tell my app to do something while it's running in the Background? What i try to do is to send a sms when i press the Power Button. This is what i wrote and it works currently while i'm inside the app:
public boolean onKeyDown(int keyCode, KeyEvent event) {
startService(new Intent(this, BackgroundService.class));
if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, "Ich brauche Hilfe! Hier ist mein aktueller Standort, kannst du mir helfen kommen?" + "\n" + "http://maps.google.com/?q=" + lat + "," + lon, null, null);
return true;
}
return super.onKeyDown(keyCode, event);
}