Android:使用意图开始任何活动 [英] Android: Using an intent to start any activity

查看:80
本文介绍了Android:使用意图开始任何活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究一个包含很多公式的应用程序.用户可以选择他们需要使用的公式,输入数字/变量,程序将返回他们想要的答案.每个公式都有自己的类,并且由于类太多,我将它们分类到单独的程序包中.

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.

例如,我可能有 3个程序包(区域 Main ).

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

  • Volume 包中,我可能有 2个类( Cube_Volume Sphere_Volume ).
  • Area 包中,我可能有 3个类(( Square_Area Circle_Area Triangle_Area ).
  • Main 包中,我可能具有 1类( Main_Activity ).
  • 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).

我目前正在尝试允许用户为自己喜欢的公式添加书签.如果用户在 Sphere_Volume 类中,则他们可以为该类添加书签.我当前正在尝试执行的操作是,当用户选择为该类添加书签时,应用程序将保存此代码返回的字符串.

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()

保存的字符串(我正在使用SQL数据库存储该字符串)将如下所示:

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

用户保存的书签(如上面显示的书签)显示在 Main_Activity 类的 Listview 中.显然,当用户单击 Listview 中的书签时,我希望程序启动相应的活动.

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.

最后,问题是:当提供的字符串类似于 com.example.area.Triangle_Area ?

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.

推荐答案

由于Intent构造函数接受组件类作为其参数,因此就这么简单:

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"));

这篇关于Android:使用意图开始任何活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆