How can I go back to my main activity after starting the Settings activity?
when the device is not connected to the internet, I send the user to the settings
st开发者_Go百科artActivity(new Intent(android.provider.Settings.ACTION_SETTINGS)
but then I'm stuck in the settings page. How can I go back to my main activity?
thanks
Jul
In that case, the user will have to explicitly go back to your activity (e.g. by pressing the back button a couple of times). I usually do this on my first Activity
in those kind of situations:
@Override
public void onResume(){
super.onResume();
// first, check connectivity
if ( isOnline ){
// do things if it there's network connection
}else{
// as it seems there's no Internet connection
// ask the user to activate it
new AlertDialog.Builder(SplashScreen.this)
.setTitle("Connection failed")
.setMessage("This application requires network access. Please, enable " +
"mobile network or Wi-Fi.")
.setPositiveButton("Accept", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// THIS IS WHAT YOU ARE DOING, Jul
SplashScreen.this.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SplashScreen.this.finish();
}
})
.show();
}
}
As you can see, I check the Internet connection in the onResume
method, so that it will check if it user activated the WiFi or not.
精彩评论