I want to send a Toast after the app launches. I'm using Android 9 so I register MyBroadcastReceiver not only on the manifest, but, in OnCreate too. After that, I use method sendBroadcast(). What I expected, OnReceive in MyBroadcast will get called but it's not.
This method is called when the BroadcastReceiver is receiving an Intent broadcast.
-Android Developers Documentation
AndroidManifest.xml:
<receiver android:name=".MyBroadcastReceiver">
</receiver>
MainActivity OnCreate():
registerReceiver(new MyBroadcastReceiver(), new IntentFilter());
Intent i = new Intent();
i.putExtra("action", 1);
sendBroadcast(i);
MyBroadcastReceiver OnReceive():
Toast.makeText(context, "toast", Toast.LENGTH_SHORT).show();