Bring application to front after user clicks on home button

后端 未结 7 888
礼貌的吻别
礼貌的吻别 2020-11-28 09:21

My application is in running mode[foreground] and user clicks on home button, which puts application to background[and still running]. I ha

7条回答
  •  借酒劲吻你
    2020-11-28 10:08

    You can use the below code to bring the application to front:

    private void bringApplicationToFront()
        {
    
            Log.d(TAG, "====Bringging Application to Front====");
    
            Intent notificationIntent = new Intent(this, MainActivity.class);
            notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
            try 
            {
                pendingIntent.send();
            }
            catch (CanceledException e) 
            {
                e.printStackTrace();
            }
        }
    

提交回复
热议问题