Create the BroadcastReceiver dynamically:
In your BroadcastReceiver class define class member:
YourMainActivity yourMain = null;
and method:
setMainActivityHandler(YourMainActivity main){
yourMain = main;
}
from your MainActivity do:
private YourBroadcastReceiverClassName yourBR = null;
yourBR = new YourBroadcastReceiverClassName();
yourBR.setMainActivityHandler(this);
IntentFilter callInterceptorIntentFilter = new IntentFilter("android.intent.action.ANY_ACTION");
registerReceiver(yourBR, callInterceptorIntentFilter);
finally, when yourBR.onReceive is fired you can call:
yourMain.methodOfMainActivity();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…