I want to simply call one function that is defined in BroadClass Activity from my AlarmManager Activity. For this I have made one broadcast Receiver and i am triggering it from Alarmmanager Activity , but I am getting no response
AlarmManager Activity ( TRIGGERING Broadcast from here)
package com.mainActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class AlarmManagerActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = new Intent(AlarmManagerActivity.this,BroadClass.class);
intent.setAction("BROADCAST_ACTION");
sendBroadcast(intent);
}
}
BroadClass Activity where I have defined the Broadcast Reciever
package com.mainActivity;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.Toast;
public class BroadClass extends Activity {
public BroadcastReceiver broadCast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
Toast.makeText(BroadClass.this, "SDK Manager Activity", Toast.LENGTH_SHORT).show();
myFunction(); //which i want to call
}
},new IntentFilter("BROADCAST_ACTION"));
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
IntentFilter filter = new IntentFilter();
filter.addAction("BROADCAST_ACTION");
registerReceiver(broadCast, filter);
super.onResume();
}
public void myFunction(){
//mycode here
}
Kindly Help me..
Thanks in advance
Have you tried removing the BroadcastReceiver setup in onResume? You’re registering a new broadcastreceiver with an empty IntentFilter.
Remember, onResume is always run after onCreate, and in your case resetting the filter that was initially set.