0

I have a button in my main Activity which sends me to the phones location settings. The problem is that when I'm pressing the back button it sends me to the Androids home screen not in my apps main Activity. As I don't have access to the settings Activity how can add the public void onBackPressed()

  • can you post the code in which you launch the phones location settings activity? – Gabriel Mar 12 '13 at 18:45
  • I think you also called `finish()` in the button `clickListener` function. Don't. – abbath Mar 12 '13 at 18:46
  • That was my fault I had finish() in the button clickListener. Now is working perfectly. Thanx a lot. –  Mar 12 '13 at 20:35

1 Answers1

0

You can override onBackPressed() method and set the intent to you main activity in it. Then pressing this button will always bring you to the main activity:

@Override
public void onBackPressed() {
   Log.d("CDA", "onBackPressed Called");
   Intent intent = new Intent(this, MainActivity.class);
   intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
   startActivity(intent);
}
Marcin S.
  • 11,161
  • 6
  • 50
  • 63