java - 从 Activity 启动浏览器,然后退出应用程序,使浏览器保持打开状态

标签 java android

首先!
好的,我正在为未在商店中托管的应用程序开发应用程序“更新系统”。我想做的是从一个 Activity 启动浏览器,然后退出应用程序,让浏览器保持打开状态。可以这样做吗?如果可以,您能指出正确的方向吗?
编辑:
我不知道这是否会改变我希望通过 AlertDialog 这样做的任何内容。

最佳答案

这是启动浏览器的方式:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.somewebsite.com"));
startActivity(browserIntent);

这就是您完成 Activity 的方式:

finish();

完成一个 Activity 与退出整个应用程序不同,因为堆栈中可能有很多 Activity。但是,您可以(并且您应该)将此任务留给系统——当没有足够的可用资源时,您的应用进程将自动终止。 供引用:Quitting an application - is that frowned upon?

编辑:带有 AlertDialog 的示例:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Launch a website?");
builder.setPositiveButton(getString(R.string.yes),
    new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("http://www.somewebsite.com"));
            startActivity(browserIntent);
            finish();
        }
    }
);
builder.setNegativeButton(getString(R.string.no),
    new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            //some other thing to do
        }
    }
);

AlertDialog dialog = builder.create();
dialog.show();

关于java - 从 Activity 启动浏览器,然后退出应用程序,使浏览器保持打开状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25017644/

相关文章:

java - BufferedReader 导致 Java GUI 挂起

Android:将参数传递给警报对话框

Java - 空整数数组

java - 绑定(bind)不匹配 : The type Foo is not a valid substitute

java - 引用私有(private)变量时,是否需要this.variableName声明?

android - AdRequest.Builder 无法解析为类型

javascript - 如何使用javascript更改android webView的字体

java - 如何读取 XML 文件?

android - 如何在 Eclipse 中过滤消息到 Logcat?

java - 获取 NPE(已编辑)