-1

我有一个应用程序,我检查用户是否在设备上启用了 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 启动器。我还检查了日志是否有任何内存泄漏或任何它没有返回到我的应用程序的其他问题,但他们没有这样的错误。

请帮我。

提前致谢

4

2 回答 2

0

我找到了我的问题答案,我android:noHistory="true"在我的清单文件中有活动。

于 2013-06-06T08:42:47.337 回答
0

像这样使用。

builder.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);
}
于 2013-06-04T11:07:37.350 回答