返回值到不同的活动 [英] Return value to a different Activity

查看:138
本文介绍了返回值到不同的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,基本上看起来像在附加的图片设计。 正如你所看到的,有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();
    ....
  }
}

这篇关于返回值到不同的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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