?将方法内创建的字符串发送到另一个类

发布于 2024-09-18 10:00:02 字数 484 浏览 4 评论 0原文

我的代码有一个活动将信息传递给第二个活动。 我可以使用此信息将第二个活动的结果中的附加信息传递给第三个活动。

我想使用手势作为返回上一个活动的方法,但如果我从第三个活动返回到第二个活动,我需要最初从第一个活动传递到第二个活动的信息仍然存在。

第一个活动

Y 是什么?

答案 y = 5

第二个活动

用户说 Y = 5

X 是什么?

第三个活动

用户说 Y = 5 X = 6

返回到第二个活动,但保持

用户所说的 Y = 5

的输入。为此,我使用了捆绑包在活动之间传递信息,但我只能从课程以意图开始。

手势控件位于另一个类中,因此我无法从此类中访问捆绑包信息,因为 getIntent 命令会产生未定义的错误。

我需要做的是能够将包中的信息从第一个活动传递到手势类,以便当我返回使用手势时可以将其传递回来。

I have code which has one activity which passes information to a second activity.
I can use this information to pass to a third activity with additional information from the result of the second activity.

I want to use gestures as a method of going back to a previous activity, but if I go back from the third to the second activity I need the information initially passed from the first to the second activity to still be present.

i.e.

First Acticity

what is Y?

answer y = 5

Second activity

User said Y = 5

what is X?

Third Activity

User said Y = 5
X = 6

Go back to Second activity but maintain the input of

User said Y = 5.

To do this I have used a bundle to pass the information between activities, but I can only access the info in the bundle from within a method within the class started by the intent.

the gesture controls are within another class, so I cannot access the bundle information from within this class as the getIntent command produces a not defined error.

What I need to do is to be able to pass the information from the bundle from the first activity to the gesture class so that I can pass it back when I go back using the gestures.

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

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

发布评论

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

评论(1

机场等船 2024-09-25 10:00:02

所以你是说当你返回时你需要能够恢复之前输入的数据?

有几个选项:

1:您可以将数据存储在应用程序对象中(可以通过 getApplication() 获取),而不是将数据与意图捆绑在一起。这将使您可以从应用程序中的任何位置访问该数据。

2:使用 SharedPreferences(如此处所述)。您只需使用字符串映射要存储的值,同样可以在应用程序中的任何位置访问该值

3:将值存储在在应用程序的整个生命周期中持久存在的任何类中的静态字段中。这是最容易执行的,但不是最好的风格(我建议仅将其用作最后的手段)

祝你好运!让我知道这是否有帮助。

So you are saying that you need to be able to recover the previously input data when you go back?

There are a couple options:

1: Instead of bundling the data with the intent, you can store the data in the application object (which you can obtain via getApplication()). This will make that data accessible from anywhere in your app.

2: Use SharedPreferences (as described here). You simply map the value you want to store with a string and it is likewise accessible anywhere in your app

3: Store the value in a static field in whatever class is persistent throughout the app's lifetime. This is the easiest to execute, but not the best style (i suggest using this as a last resort only)

Good Luck! Let me know if this was helpful.

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