从服务机器人开始活动机器人

2023-09-11 10:43:38 作者:稳拿感情刀

Android的:

public class LocationService extends Service {

@Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
        startActivity(new Intent(this, activity.class));
    }
}

我公司推出的活动

活动如果条件满足启动

startService(new Intent(WozzonActivity.this, LocationService.class));

这是我的 LocationService 上述无法启动活动,我怎么能得到当前的环境中运行活动服务类?

from my LocationService mentioned above could not launch Activity, how can I get context of current running Activity in service class?

推荐答案

在服务类中

Intent dialogIntent = new Intent(this, myActivity.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(dialogIntent);