如何开始从服务的活动?

2023-09-11 20:11:34 作者:痴心病友

是否有可能开始从服务的活动?如果是的话,我们如何才能做到这一点?

Is it possible to start an Activity from a Service? If yes, how can we achieve this?

推荐答案

android.app.Service 的后裔 android.app.Context 这样你就可以 startActivity 直接使用。但是,因为你开始这个你需要设置 FLAG_ACTIVITY_NEW_TASK 标志对意图的任何活动之外。

android.app.Service is descendant of android.app.Context so you can use startActivity directly. However since you start this outside any activity you need to set FLAG_ACTIVITY_NEW_TASK flag on the intent.

例如:

Intent i = new Intent();
i.setClass(this, MyActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);

其中,为您服务。

相关推荐
 
精彩推荐
图片推荐