Search code examples
androidandroid-studiomathfavorites

how to add activity through favourite button


i am currently working on a maths application.I want to add a favourite button through which the user can add it to the favourite list.Till now i have added the favourite button but how to add the activity to the favourites when a user clicks it.can anybody tell me???


Solution

  • Sounds like you're trying to create a list of the user's favorite Activities in a String list? To do this...

    1. get the name of the Activity using String mActivityName = this.getClass().getSimpleName();

    2. create an ArrayList using ArrayList mFavList; which will collect the Activity names.

    3. Set an OnClickListener on the button which will add the Activity name to the ArrayList mFavList.add(mActivityName)