Android How to stop AlarmManager in other Activity

喜夏-厌秋 提交于 2019-12-05 22:09:55

In Activity B you should create sIntent with the same context as you created it in Activity A.

So in Activity A I would add this

private static Context context;

public static Context getAppContext(){
    return ActivityA.context;
}

and inside onCreate() method of Activity A, initialize context

context=getApplicationContext();

And in Activity B create sIntent like this:

Intent intent = new Intent(ActivityA.getAppContext(), ServiceClass.class);
intent.putExtra("fsasf", "bar");
PendingIntent pintent = PendingIntent.getService(this, 0, intent, 0);
AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
stopService(intent);
alarm.cancel(pintent);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!