How to use getApplicationContext in BroadcastReceiver class?

前端 未结 3 1291
醉话见心
醉话见心 2021-01-11 19:22

I am using the broadcaster class to listen to sms messages using this code

package com.escortme.basic;

import android.content.BroadcastReceiver;
import and         


        
3条回答
  •  北恋
    北恋 (楼主)
    2021-01-11 19:37

    Look at the method signature for onReceive()

    public void onReceive(Context context, Intent intent) {
    

    You are being passed a context as a parameter. You should be using that context when you need one.

    Pol_ViewActivity appState = ((Pol_ViewActivity)context); 
    

    EDIT: also I don't know exactly what it is you are trying to do. But you probably shouldn't be trying to obtain an Activity object and call a method on it like you seem to be doing.

提交回复
热议问题