我们可以将一个活动调用到另一个活动中吗?

发布于 2024-11-28 14:08:35 字数 50 浏览 1 评论 0原文

我的意思是我想将一个活动使用到另一个活动中,就像使用该类的创建实例的类一样。是否可以?

I Mean that i want to use one activity into another activity, Like class using create instance of that class. Is it Possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

掩于岁月 2024-12-05 14:08:35

好吧,我认为你应该使用意图从另一个活动调用一个活动。

从您的活动中调用此方法:

Intent in = new Intent(getApplicationContext(), NextActivity.class);
startActivity(in);

Well, I think you should use Intents to call an activity from another activity.

Call this from your Activity:

Intent in = new Intent(getApplicationContext(), NextActivity.class);
startActivity(in);
缺⑴份安定 2024-12-05 14:08:35

你只需说 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 its onCreate() method gets called, but when you say new MyActivity() its default constructor is called and not its onCreate() method (which Android OS will not accept). so always say startActivity() or startActivityForResult() which are handled by android OS

转身泪倾城 2024-12-05 14:08:35

从要运行活动的位置编写此代码

Intent intent = new Intent(current_Activity_name.this,New_Activity_name.class);
                    startActivity(intent);

并将以下代码添加到清单文件中

<activity android:name=".New_activity_name" />

Write this code from where you want to run activity

Intent intent = new Intent(current_Activity_name.this,New_Activity_name.class);
                    startActivity(intent);

And add the following code into manifest file

<activity android:name=".New_activity_name" />
暮色兮凉城 2024-12-05 14:08:35

好吧,由于活动是一个可显示窗口,因此适当的概念是一个活动可以从另一个活动“启动”。这是实现这一目标的方法:

Intent i = new Intent(CurrentActivity.this, NewActivity.class);
CurrentActivity.this.startActivity(i);

此代码片段可以从 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:

Intent i = new Intent(CurrentActivity.this, NewActivity.class);
CurrentActivity.this.startActivity(i);

This code snippet can launch NewActivity from any point in the CurrentActivity code, for example, an 'OnClickListener'.

时光匆匆的小流年 2024-12-05 14:08:35

是的,这是可能的。这是通过意图来实现的。

Intent intent = new Intent(this.getApplication(), TARGET_ACTIVITY_NAME.class);
//To add data use intent.putExtra(NAME,VALUE);
intent.setData(data.getData());
try
{
    startActivity(intent); // This ll launch the TARGET_ACTIVITY_NAME
}       
catch(Exception e)
{
}

有关更多信息,请参阅此链接

沙什

Yes, it is possible. This is achieved through Intents.

Intent intent = new Intent(this.getApplication(), TARGET_ACTIVITY_NAME.class);
//To add data use intent.putExtra(NAME,VALUE);
intent.setData(data.getData());
try
{
    startActivity(intent); // This ll launch the TARGET_ACTIVITY_NAME
}       
catch(Exception e)
{
}

For more information refer this link.

Shash

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文