public void open(){
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage(getApplicationContext().getResources().getString(R.string.searchFilterLocationMessage));
alertDialogBuilder.setPositiveButton(R.string.Ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
/*Intent intent = new Intent(Settings.ACTION_SETTINGS) ;
this.startActivity(intent);
*/
startActivityForResult(new Intent(Settings.ACTION_SETTINGS), 0);
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0) {
Intent intent = getIntent();
finish();
startActivity(intent);
}
}//onActivityResult
Launching an Activity
whith the singleTask
launch mode by calling startActivityForResult(intent, requestCode)
returns a cancel result immediately. You can see it in debugger that onActivityResult()
is called even before the system settings Activity
starts.
As a quick workaround I suggest using a flag indicating whether the settings Activity
was called or not. Like
setting a flag
private boolean flag = false;
using startActivity()
istead of startActivityForResult()
@Override
public void onClick(DialogInterface arg0, int arg1) {
startActivity(new Intent(Settings.ACTION_SETTINGS));
flag = true;
}
checking the flag in onResume()
@Override
protected void onResume(){
super.onResume();
if (flag) {
startActivity(new Intent(this, MainActivity.class));
finish();
}
}
Launch the setting intent:
startActivity(new Intent(Settings.ACTION_SETTINGS));
and fetch the current Activity in onResume()
method:
public void onResume(){
super.onResume();
// Do your work
}
After getting back from the setting screen, your onResume()
method will be call and here you can fetch your location.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With