Search code examples
androidandroid-intentbroadcastreceiver

static broadcast gives error


I have a broadcast receiver and im again broadcasting message from that broadcast onreceive's method .

public static class MyBroadcastReceiver extends BroadcastReceiver
{

    @Override
    public void onReceive(Context context, Intent intent)
    {
        // TODO Auto-generated method stub
        Intent intent1 = new Intent("com.test.test");
        sendBroadcast(intent1); 
    }
}

But it gives error on sendBroadcast

cannot make a static reference to the non-static method sendbroadcast(intent) 
from the type context wrapper.

please help me solving this issue.


Solution

  • Use

        context.sendBroadcast(intent1); 
    

    instead of

        sendBroadcast(intent1); 
    

    because sendBroadcast is not method of BroadcastReceiver class.