Java android中的隐式意图问题
在我的android应用程序中,我使用Java android中的隐式意图问题,java,android,android-intent,Java,Android,Android Intent,在我的android应用程序中,我使用隐式意图打开位置服务。我想在打开服务后重新启动应用程序。如何检查位置服务的结果并重新启动应用程序 我使用下面的代码 AlertDialog.Builder dialog = new AlertDialog.Builder(Splash.this); dialog.setMessage("Location not enabled"); dialog.setPositiveButton("open settings", new DialogInterfa
隐式意图
打开位置服务
。我想在打开服务后重新启动应用程序。如何检查位置服务的结果
并重新启动应用程序
我使用下面的代码
AlertDialog.Builder dialog = new AlertDialog.Builder(Splash.this);
dialog.setMessage("Location not enabled");
dialog.setPositiveButton("open settings",
new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface paramDialogInterface,int paramInt)
{
// TODO Auto-generated method stub
Intent myIntent = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(myIntent);
}
});
dialog.setNegativeButton("cancel",
new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface paramDialogInterface, int paramInt)
{
// TODO Auto-generated method stub
finish();
}
});
dialog.show();
当我从位置服务
按后退按钮时,我想使用下面的代码重新启动我的活动
Intent myIntent = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(myIntent);
谢谢。使用startActivityForResult
@Override
public void onClick(View v)
{
startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 1);
}
并在ActivityResult中检查以确认
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode==RESULT_OK)
{
if(resultCode == RESULT_OK && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
{
Button bt = (Button)findViewById(R.id.turnGPS);
bt.setVisibility(View.INVISIBLE);
this.finish();
}
else if(resultCode == RESULT_CANCELED)
{
Toast.makeText(getBaseContext(), "No GPS device or service enabled", Toast.LENGTH_LONG+Toast.LENGTH_LONG).show();
}
}
super.onActivityResult(requestCode, resultCode, data);
}
希望能有帮助
注意:我假设您的SplashScreen的启动模式
不是单任务
在logcat中没有问题。我想在从SplashScreen打开位置服务后加载MainActivity。但它仍然停留在启动活动上,同时按下位置服务页面上的后退按钮。然后我关闭应用程序并再次打开,现在它转到MainActivity。