Android的刷新活动时,返回到它 [英] Android Refresh activity when returns to it

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

问题描述

我需要一些帮助,在我的应用程序刷新我的活动之一。我使用的标签主机活动,并从我的子活动之一,连接到Web服务和下载一些数据。当我在$我的孩子活动p $ PSS同步按钮,我开始一个新的活动,这是不是在标签主机和当同步完成,它返回到它的父(子活动)。我想实现的事情是刷新活动时,我返回到它。当我检查在互联网上我发现,最好的选择是用做 startActivityForResult ,但我真的不知道如何使用,以及如何刷新活动时,我从成品活动得到的结果。

如果有人能帮助我,我会真的glad.Thanks!

编辑:

我用这个code和它甚至没有显示在 onActivityResult

日志

MyCollectionId.class:

 意向意图=新的意图(MyCollectionId.this,Synchronization.class);
intent.putExtra(进程,2);
startActivityForResult(意向,1);

@覆盖
保护无效onActivityResult(INT申请code,INT结果code,意图数据){
 super.onActivityResult(要求code,因此code,数据);
 如果(结果code == RESULT_OK){
     Log.e(,OnActivityResult);
    意图刷新=新的意图(这一点,MyCollectionId.class);
    startActivity(刷新);
    this.finish();
 }
}
 

Synchronization.class:

 意向意图=新的意图();
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
的setResult(RESULT_OK,意图);
完();
 

解决方案

另一个棘手的方式做,这是刚开始你对 onRestart活动()

  @覆盖
公共无效onRestart(){
    super.onRestart();
    意图previewMessage =新的意图(StampiiStore.this,StampiiStore.class);
    TabGroupActivity parentActivity =(TabGroupActivity)的getParent();
    parentActivity.startChildActivity(StampiiStore,previewMessage);
    this.finish();
}
 

这是应该做的伎俩其实。 (在此code我展示它,当你使用自定义TabActivity经理做的方式。)

I need a little help with refreshing one of my activities in my application. I'm using tab host activity and connecting to web service and downloading some data from one of my child activities. When I press sync button in my child activity I'm starting a new activity which is not in tab host and when the sync is done, it returns to it's parent (child activity). The thing that I want to achieve is to refresh the activity when I return back to it. As I checked over the internet I find that the best option to do it is using startActivityForResult,but I don't really understand how to use that and how to refresh the activity when I receive the result from the finished activity.

If anyone can help me, I'll be really glad.Thanks!

EDIT:

I'm using this code and it's not even showing the Log in onActivityResult

MyCollectionId.class :

Intent intent = new Intent(MyCollectionId.this, Synchronization.class);
intent.putExtra("process", 2);
startActivityForResult(intent, 1);

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 super.onActivityResult(requestCode, resultCode, data);
 if(resultCode==RESULT_OK){
     Log.e("","OnActivityResult");
    Intent refresh = new Intent(this, MyCollectionId.class);
    startActivity(refresh);
    this.finish();
 }
}

Synchronization.class :

Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
setResult(RESULT_OK,intent);
finish();

解决方案

Another tricky way to do this is just start your activity on onRestart()

@Override
public void onRestart(){
    super.onRestart();
    Intent previewMessage = new Intent(StampiiStore.this, StampiiStore.class);
    TabGroupActivity parentActivity = (TabGroupActivity)getParent();
    parentActivity.startChildActivity("StampiiStore", previewMessage);
    this.finish();
}

That should do the trick actually. (In this code I'm showing the way it's done when you are using a custom TabActivity manager.)

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

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