Hi folks how I can implement a Broadcast receiver in an activity that receives intent from a service along with some parameter’s of int and string type?
UPDATE:
I have this under the Activity:
private BroadcastReceiver ReceivefrmSERVICE = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "IN DA BroadCASTER",
Toast.LENGTH_LONG).show();
}
};
and I have this under a function in the service that is called on a event from another activity when a checked button is checked:
public void switchSpeaker(int hr, int min){
Toast.makeText(Server.this, hr +" , " +min, Toast.LENGTH_LONG).show();
Intent intent = new Intent(this, andRHOME.class);
//intent.putExtra("sendMessage","1");
startActivity(intent);
/*PendingIntent pi = PendingIntent.getService(Server.this, 0, myIntent, 0);
AlarmManager almmgr = (AlarmManager) getSystemService(ALARM_SERVICE);
Calendar cldr = Calendar.getInstance();
int min1 = cldr.get(Calendar.MINUTE);
cldr.setTimeInMillis(System.currentTimeMillis());
cldr.add(Calendar.SECOND, 30);
almmgr.set(AlarmManager.RTC_WAKEUP, cldr.getTimeInMillis(), pi);*/
}
But its crashing?? ,What to do?
in onResume: (so you receive only while in foreground)
in onPause: (the try catch is to fix a bug in unregister in case it is called twice)