返回值到不同的活动返回值、不同

2023-09-12 05:13:13 作者:高美男i

我有一个应用程序,基本上看起来像在附加的图片设计。 正如你所看到的,有4个活动,一些活动有碎片。

I have an app that basically looks like the design in the attached picture. As you can see, there are 4 activities, and some of the activities have fragments.

我希望得到一个测试的答案返回给用户的配置文件。 到现在为止,我已经上传结果到服务器,不必每次应用程序更新用户的个人资料,他们回去的 ProfileActivity ,但似乎是在浪费资源。

I want to get the answer of a test back to the user's profile. Up to now, I've been uploading the result to the server and having the app update the user's profile every time they go back to the ProfileActivity, but that seems like a waste of resources.

有没有一种模式或办法做到这一点的应用程序吗? 我看着这个:这似乎是可行的,如果我能以某种方式连接两个 startActivityForResult()秒。

Is there a pattern or way to do this in the app? I looked at this: which seems doable if I can somehow link two startActivityForResult()s.

我看着使用这个问题但我不能得到的实例在 UserFragment 到 TestActivity

I looked into using the delegate pattern described in this question but I can't get the instance of the UserFragment to the TestActivity.

我希望有人能在这样做的正确方法的方向指向了我。

I hope someone can point me in the direction of the correct way of doing this.

推荐答案

一种方法是使用 startActivityForResult()没有完成任何活动

One approach is use startActivityForResult() don't finish any Activity

首先 startActivityForResult的所有活动()然后根据您的病情就可以完成的活动。

start all activities by startActivityForResult() then depending on your condition you can finish activity

通过结果回用previous活动 onActivityResult()

pass result back to the previous activity using onActivityResult()

那么对于片段,您可以在 ProfileActivity 存储片段的对象。 在更新UI片段写入方法

Then for fragment you can store fragment object in ProfileActivity . In Fragment write method for updating UI

所以,你可以使用片段对象访问方法

So you can access that method using fragment object

class ProfileActivity extends ......
{
  @override
  public void onActivityResult(....)
  {
    .....
    frgamnetObject.updateUI();
    ....
  }
}
 
精彩推荐