Boot broadcast receiver is not working and there is nothing in onReceive()
public class BootReceived extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Toast.makeText(context, intent.getAction(), Toast.LENGTH_LONG).show();
Log.d("IfWalaBooot", intent.getAction());
Intent intent1 = new Intent(context, MainActivity.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent1);
Intent tni = new Intent(context, MainService.class);
tni.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startService(tni);
}
}
You need to use registerReceiver in order to work in android oreo & above. Starting from oreo there is background restriction.
You can use this link to learn about it. https://www.journaldev.com/23653/android-oreo-implicit-and-explicit-broadcast-receiver
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.