Search code examples
javaandroidgoogle-apps

Change Title/Label of an Activity in Android 5 recents screen


With Android 5, Google supports multiple activities in the recents screen for a single application. I managed to implement multiple activities in the recents screen with this official doc. How can I change the title of the activity? Switching to recents screen always shows my app name as title.

Activity.setTitle("title"); 

changes the title on the toolbar, but I want it to change in the recents screen, just like Google does in Google Chrome App.

I need to change the title programatically.


Solution

  • In your activity you can use new method:

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.secondary_layout);
        setTaskDescription(new ActivityManager.TaskDescription("Activity 2"));
    }
    

    setTaskDescription sets information about activity in recents task list. In this example only title.