How to bring Android existing activity to front via notification

后端 未结 4 2038
醉酒成梦
醉酒成梦 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:26

    I'd recommend you do this,

    private void showNotification () 
    {
    
    Intent toLaunch = new Intent(getApplicationContext(), DummyActivity.class);
    
    // You'd need this line only if you had shown the notification from a Service
    toLaunch.setAction("android.intent.action.MAIN");
    
    PendingIntent intentBack = PendingIntent.getActivity(getApplicationContext(), 0,toLaunch, PendingIntent.FLAG_UPDATE_CURRENT);
    
    .... 
    }
    

    The DummyActivity should simply be an activity that always finishes itself in the oncreate event.

    In the manifest file, add these lines

    
        
            
        
    
    

    I hope this helps ...

提交回复
热议问题