How to bring Android existing activity to front via notification

后端 未结 4 2049
醉酒成梦
醉酒成梦 2020-12-06 10:46

I have one Android application, when it runs a service, I want to show the notification on the status bar. Then the user could navigate to other application by pressing HO

4条回答
  •  误落风尘
    2020-12-06 11:28

    private void showNotification() {
        Intent toLaunch = new Intent(getApplicationContext(), MySingleTopActivity.class);
    
        //add these two lines will solve your issue
        toLaunch.setAction("android.intent.action.MAIN");
        toLaunch.addCategory("android.intent.category.LAUNCHER");
    
        PendingIntent intentBack = PendingIntent.getActivity(getApplicationContext(), 0, toLaunch, PendingIntent.FLAG_UPDATE_CURRENT);
    
        notification.setLatestEventInfo(getApplicationContext(), getText(R.string.GPS_service_name), text, intentBack);
        ...
    }
    

提交回复
热议问题