yahya labeeb
yahya labeeb

Reputation: 1

open MainActivity by BroadcastReceiver

my code to open MainActivity and show NOTIFICATION after the time is end by AlarmManager and BroadcastReceiver the NOTIFICATION go fine but the MainActivity doesn't shown my phone android 10 this the code

        Intent launch_intent = new  Intent(context, MainActivity.class);
        launch_intent.setComponent(new 
        ComponentName("com.example.mysajedn","com.example.mysajedn.MainActivity"));
        launch_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_ACTIVITY_SINGLE_TOP
            | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT
            |Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
 
       launch_intent.addCategory(Intent.CATEGORY_LAUNCHER );
       context.startActivity(launch_intent);

    NotificationHelper notificationHelper = new NotificationHelper(context);
    NotificationCompat.Builder nb = notificationHelper.getChannelNotification();
    notificationHelper.getManager().notify(1, nb.build());

where the problem

Upvotes: 0

Views: 58

Answers (1)

Dan Harms
Dan Harms

Reputation: 4840

Beginning in Android 10 (API 29), you can no longer start activities from a background process like a BroadcastReceiver.

https://developer.android.com/guide/components/activities/background-starts

Upvotes: 1

Related Questions