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!