I use a button to exit my app,however,when I am exit it and press the recent app button(picture below)and re-enter my app through the grey screen,instead of starting the app from the main activity,its start from the recent activity and crash because it has bo data..even when the app is crashed,when I press again on the gray activity its open the second activity again and crash again..
Picture of the grey screen( https://ibb.co/TqPnXJR )
How can I fix it that when the user click on the grey screen it will launch the main activity?
This is my code:
AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Stop Navigation "); builder.setMessage("Are you sure you want to stop navigation?"); builder.setCancelable(false); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { exitButtonPressed = true; Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); //finishAffinity(); //System.exit(0); //finishAndRemoveTask(); //android.os.Process.killProcess(android.os.Process.myPid());// I TRIED ALL THE ABOVE BUT ITS ITS NOT WORKING.. } });
Thank you !!
EDIT:
When click on the gray square it activates OnResume..
I noticed that every time I remove my task and enter through my foreground service to the second activity its happening.I think its about the pending intent.
this is my pending intent code:
Intent i = new Intent(getApplicationContext(), MapsActivity.class);i.putExtra("AddressBackground22", mAddress);i.putExtra("AddressType22", mAddressType);i.putExtra("AddressLatBackground22", destinationLat);PendingIntent activityPendingIntent = PendingIntent.getActivity(this, 25, i, 0); NotificationCompat.Action action2 = new NotificationCompat.Action(R.drawable.ic_cancel, getString(R.string.remove_location_updates), servicePendingIntent);NotificationCompat.Action action = new NotificationCompat.Action(R.drawable.ic_launch, getString(R.string.launch_activity), activityPendingIntent); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID); Notification notification = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID) .setContentTitle("App is running in background") .addAction(action) .addAction(action2) .setColor(getColor(R.color.foreGroundBackgroundColor)) .setPriority(NotificationManager.IMPORTANCE_HIGH) .setCategory(Notification.CATEGORY_SERVICE) .setSmallIcon(R.drawable.applogo) .build();