0

I am setting up an application and need to have a favourites button in an activity to add the activity to a favourites table. I have a Facebook Login set up with SQLite database storing the email. I was wondering how to save an activity to my favourites and have it stored in the SQLite Database?

I have seen code such as:

btnAddFavourite = (ImageButton) findViewById(R.id.btnAddFavourite);

btnAddFavourite.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        // Add code here to save the favourite, e.g. in the db.
    }
});

btnAddFavourite.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {

            // Open the favourite Activity, which in turn will fetch the saved favourites, to show them.
            Intent intent = new Intent(getApplicationContext(), FavViewActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            getApplicationContext().startActivity(intent);

            return false;
        }
    });

But I am not sure what code to add in to be able to save the activity to my favourites in the SQLite Database.

Possible Solution - I believe SharedPreferences could be used but how do you save the whole activity?

Therefore when the user goes to their favourites page, they have a button to go to that activity they saved

I would really appreciate your help.

Thank you so much in advance!

User10
  • 27
  • 5
  • You should google for tutorials on using SQLLite. – IAmGroot May 19 '16 at 16:31
  • Can you describe what you mean by "save the activity"? An activity is just code used to provide some interaction with the user. What information do you need to save? – adelphus May 19 '16 at 16:46
  • I have a button to go to an activity, i.e. I have an activity to go to a pub and I want to save that pub to my favourites, therefore when the user clicks the 'save to favourites' the pub gets added to their favourites activity. – User10 May 19 '16 at 16:59
  • Question updated with possible solution – User10 May 19 '16 at 17:09

1 Answers1

0

your solution as i understand will be that you can get your activity name and save it in db. after that when you want to return to that activity get the name of activity and after that start activity with its name. to get name of activity use the this.getClass().getSimpleName(); and to start activity from its name as string use : startActivity(this, Class.forName(yourStringClass));

for more information about getting name of activity and start activity from string name refer to links bellow:

Get Activity name dynamically - android

Intent and start activity from string

Community
  • 1
  • 1
pouyan
  • 3,445
  • 4
  • 26
  • 44