【问题标题】:Call an implecit intent for perticular time interval调用特定时间间隔的隐式意图
【发布时间】:2017-09-11 10:58:57
【问题描述】:

我想在隐式意图的帮助下从我的应用程序启动另一个应用程序,并希望第二个活动在特定的时间间隔后停止。

例如: 要打开 chrome,我可以这样做

 String url = "http://www.example.com";
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.setPackage("com.android.chrome");
    try {
        startActivity(i);
    } catch (ActivityNotFoundException e) {
        // Chrome is probably not installed
        // Try with the default browser
        i.setPackage(null);
        startActivity(i);
    }

但我希望 chrome 在 1 分钟后自动关闭。有没有办法做到这一点?

【问题讨论】:

  • 你添加 Handler、TimerTask、Runnable、任何形式的线程并添加时间间隔、postDelayed、sleep 以添加延迟

标签: android android-intent startactivityforresult


【解决方案1】:

是的,您可以终止应用程序;首先,您必须通过ActivityManager 找到正在运行的应用程序,如下所示:

How to find the currently running applications programatically in android?

然后你可以像这里暗示的那样杀死它:

How to kill all running applications in android?

虽然我和谷歌并不真正推荐这个>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-15
    • 1970-01-01
    • 2011-06-04
    • 1970-01-01
    • 2010-10-29
    • 2011-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多