1

okay i am making a Quote Application and was wondering how can i have an intent that can bookmark a specific activity? So what i want is when the user clicks a button it bookmarks the activity into another activity that holds the bookmarks/favortites. Can someone explain this to me? Or a simple tutorial?

Here is the code i have: i want to know how i can add this code to program a button to create a new button in another activity? : `Button btn=new Button(this);

btn.setId(btn);

btn.setBackgroundResource(R.drawable.image);

btn.setMinimumHeight(150);

btn.setMinimumWidth(150);

Relativelayout.addView(btn); `

Thanks, any help is highly appreciated, Im just a noob wanting to learn.;)

Moussa
  • 851
  • 3
  • 10
  • 19
  • to whoever voted down, i want to ask why? im asking a question and trying to learn and you have a problem? what did i do to you? – Moussa Aug 21 '12 at 17:20

3 Answers3

1

It needs some logic, jsut make when the Bookmarking button is clicked, create an intent inside the Bookmarks activity which refers to bookmarked activity.

Example:

Activity 1 has a button called Bookmark. when I click the button, in Activity 2 which is the bookmarks a new button is created that refers to Activity 1.

John Jared
  • 790
  • 3
  • 16
  • 40
1

I think you're making the situation too complicated. It sounds like you want to simply create and store a list of classes, then access that list from another activity.

First, when the user clicks the button to record a bookmark, I would recommend storing the name of the class in SharedPreferences. SharedPreferences allows you to store name-value pairs into a file to be accessed at a later time from any activity.

SharedPreferences sp = this.getSharedPreferences("file_name", MODE_PRIVATE);
Editor editor = sp.edit();
editor.putString("class_name", "your.class.path.TestClassActivity");
editor.commit();

Later on, you can access the all the saved class names. See here for a way to get all the keys in the SharedPreferences file.

Finally, once you have all the class names, you can use them to build your intents.

String myClass = "TestClassActivity";
Class<?> cl = null;
try {
    cl = Class.forName(myClass);
} catch (ClassNotFoundException e) {
    e.printStackTrace();
}
Intent myIntent = new Intent(getApplicationContext(), cl);
startActivity(myIntent);

EDIT: I've created an example project where the above is used. It can be downloaded from www.sourceforge.net/projects/androidbookmark/

Community
  • 1
  • 1
Greg
  • 733
  • 6
  • 14
  • Hey Greg can you make a sapmple Project and send to me email or upload it to mediafire or another website? – Moussa Aug 21 '12 at 17:41
  • For future reference, other users can't see your email or contact you directly...I've given you most of the code you need though. Now that you know how to save the class names in one activity, retrieve them in another, and set up your intents, the rest is just a matter of implementing it in your project. Best of luck. – Greg Aug 21 '12 at 20:54
0

Not sure I got your problem, but it looks like you got wrong app design. I suspect you display many quote (citation of someone?) in single activity. So all you need to store is id of that quote to display and then, when user'd hit the button, fire your QuoteActivity and pass stored quote in bundle.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141