【发布时间】: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