I want to send broadcast message to an application and then receive it from current activity. I can send broadcast message but then it couldn't received from broadcast receiver. Here is my code;
public class LogIn extends Activity {
private BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//toast message received !
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getActionBar();
//send broadcast message
Intent i = new Intent(LogIn.class.getName());
getContext().sendBroadcast(i);
}
@Override
protected void onResume() {
super.onResume();
registerReceiver(receiver, new IntentFilter(LogIn.class.getName()));
}
@Override
protected void onPause() {
super.onPause();
try {
unregisterReceiver(receiver);
} catch (Exception e) {}
}
}
What is the problem that I missed ? Thank you for your help..