Call Notification from BroadcastReceiver

前端 未结 1 370
猫巷女王i
猫巷女王i 2021-01-06 02:54

I have the code :

public void AlarmStart() {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MINUTE, 5);
    Intent intent = new Intent(MainN         


        
1条回答
  •  一整个雨季
    2021-01-06 03:38

    I think that you don't need any reference to an Activity in the NotifierHelper. Use the Context (which Activity is a subclass of), eg:

    public static void sendNotification(Context caller, ...
    

    Such methods as getSystemService(), etc.. are actually exposed by Context.

    And since you get passed a Context in AlarmReceiver.onReceive(), you can pass it on.

    0 讨论(0)
提交回复
热议问题