P
P
peregrinTuk2019-06-14 20:17:28
Java
peregrinTuk, 2019-06-14 20:17:28

How to call the desired intent from the service?

Weh welcome!
Help me figure it out, since I just started studying android for a couple of weeks and ran into a problem.
In my application, the service starts at startup

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        startService(new Intent(getApplicationContext(), MyService.class));
    }

This service checks if there is a message for the user, and if so, a notification is displayed to the user through the showNotification method. In the showNotification method, I process a click on the notification so that the user gets into the application in MainActivity
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

But when the user clicks on the notification, the application starts and immediately knocks out that an error has occurred in the transfer and the application dies.
Tell me how to fix this?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question