0

I have been working on an application that has a bunch of formulas in it. The user can select which formula they need to use, input the numbers/variables, and the program will return whatever answer they are looking for. Each formula has its own class and since there are so many classes I sorted them into separate packages.

For Example, I might have 3 packages (Volume, Area, and Main).

  • In the Volume package, I might have 2 classes (Cube_Volume, and Sphere_Volume).
  • In the Area package, I might have 3 classes (Square_Area, Circle_Area, and Triangle_Area).
  • In the Main package, I might have 1 class (Main_Activity).

I am currently trying to allow the user to bookmark their favorite formulas. If a user is in the Sphere_Volume class, they can bookmark that class. How I am currently attempting to do this is when the user chooses to bookmark the class, the application saves the string returned by this code.

this.getLocalClassName() 

The string that is saved (I am using an SQL database to store the string) will look something like this:

com.example.area.Triangle_Area 

The bookmarks that the user saves (like the one shown above) are displayed in a Listview in the Main_Activity class. Obviously, when the user clicks on a bookmark in the Listview, I would like the program to start the corresponding activity.

So finally, the question is: How can I use an Intent to start any activity in any other package when the string provided is something like com.example.area.Triangle_Area?

Thanks for any and all answers! Please comment if I need to elaborate more on my issue.

1 Answer 1

1

Since Intent constuctor accepts the component class as its parameter, it's as simple as this:

context.startActivity(new Intent(context, Class.forName("com.example.area.Triangle_Area")); 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the quick and correct answer! Just to clarify for anyone who is gonna use this answer, you can replace "com.example.area.Triangle_Area" with any string variable that equals getLocalClassName(). Thanks again!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.