我有一个应用程序,我检查用户是否在设备上启用了GPS和无线位置。如果它不启用,那么我startActivity启用它们。我的代码是:
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
|| !locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.gps_not_found_title); // GPS not found
builder.setMessage(R.string.gps_not_found_message); // Want to enable?
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
});
builder.setNegativeButton("Cancel", null);
builder.create().show();
return;
}
上面的代码然后启动我的位置活动为用户启用GPS和无线定位。之后,如果我按后退按钮,它应该回到我的应用程序活动,但它显示android启动器。我还检查了日志中的任何内存泄漏或任何其他问题,因为它没有返回到我的应用程序,但他们没有这样的错误。
请帮帮我。
Thanks In Advance
像这样使用。
建设者。setNegativeButton("取消",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.cancel();
}
});
alertDialog.show();
返回键按
WebView wt;//i used and given example by using webview
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_DOWN){
switch(keyCode)
{
case KeyEvent.KEYCODE_BACK:
if(wt.canGoBack() == true){
wt.goBack();
}
else{
this.finish();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}
我找到了我的问题答案,我有android:noHistory="true"
在我的清单文件的活动。