我们可以将一个活动调用到另一个活动中吗?
我的意思是我想将一个活动使用到另一个活动中,就像使用该类的创建实例的类一样。是否可以?
I Mean that i want to use one activity into another activity, Like class using create instance of that class. Is it Possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
好吧,我认为你应该使用意图从另一个活动调用一个活动。
从您的活动中调用此方法:
Well, I think you should use Intents to call an activity from another activity.
Call this from your Activity:
你只需说
startActivity()
就可以做到这一点,没有其他办法。您无法创建 Activity 的实例,因为当调用其onCreate()
方法时,就会创建 Activity,但是当您说new MyActivity()
时,它的默认构造函数是调用而不是其onCreate()
方法(Android 操作系统不会接受)。所以总是说由android OS 处理的
startActivity()
或startActivityForResult()
you can do it only by saying
startActivity()
, no other go. you can't make an instance of Activity because , an Activity gets created when itsonCreate()
method gets called, but when you saynew MyActivity()
its default constructor is called and not itsonCreate()
method (which Android OS will not accept). so always saystartActivity()
orstartActivityForResult()
which are handled byandroid OS
从要运行活动的位置编写此代码
并将以下代码添加到清单文件中
Write this code from where you want to run activity
And add the following code into manifest file
好吧,由于活动是一个可显示窗口,因此适当的概念是一个活动可以从另一个活动“启动”。这是实现这一目标的方法:
此代码片段可以从
CurrentActivity
代码中的任何点启动NewActivity
,例如“OnClickListener”。Well, since an Activity is a displayable-window, the appropriate concept would be that one Activity can be "launched" from another. This is how you achieve that:
This code snippet can launch
NewActivity
from any point in theCurrentActivity
code, for example, an 'OnClickListener'.是的,这是可能的。这是通过意图来实现的。
有关更多信息,请参阅此链接。
沙什
Yes, it is possible. This is achieved through Intents.
For more information refer this link.
Shash