English 中文(简体)
对儿童意图的影响
原标题:TabActivity pass extras to child intents
  • 时间:2010-12-03 00:40:44
  •  标签:
  • android

I have three activities:

<>A-显示网站的数据清单。 根据这项活动,你可以采取行动,在这份清单中增加一些内容(活动B)。

www.un.org/Depts/DGACM/index_french.htm 成功完成这项活动后,将需要告诉活动A,以更新其清单。

www.un.org/Depts/DGACM/index_spanish.htm 活动T-A TabHost, 其中载有活动A。

我的问题是:

活动B需要记述活动A,但活动意图必须是活动T,因为我希望大街展示活动A。

//ActivityB.class
Intent myIntent = new Intent(v.getContext(), ActivityT.class);
myIntent.putExtra("target", "ActivityA");
myIntent.putExtra("refreshData", true);
startActivityForResult(myIntent, 0);

I thought I could use the TabHost as an intermediary and just pass the extras through to Activity A if they were set, like so:

//ActivityT.class
Bundle extras = getIntent().getExtras();

// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, ActivityA.class);

// Check to see if we want to pass our bundle through to the activity
if (extras != null && extras.getString("target").equals("activityA")) {
     intent.putExtras(extras);
}

// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("Tab1").setIndicator("Tab1",
            res.getDrawable(R.drawable.ic_tab_tab1)).setContent(intent);
tabHost.addTab(spec);

除了我改用不同的表格和回头换面时,外面再转,这又一次导致我每次复读数据,尽管我已经不再从B活动中提取。 这是因为“贱民”在制片变化中重新抬头,因此,这笔钱总是传给孩子。

因此,我如何把活动A从活动B中恢复过来,但还是让塔霍斯特站起来?

最佳回答

虽然也许不是最棘手的解决办法,但我还是利用我从活动B中可以确定的我的“活动”类静态数据成员。

//ActivityA.class

public static boolean refreshData = false;

public void onResume() {
    if (refreshData) {
         mRefreshData();
         refreshData = false;
    }
}

//ActivityB.class

ActivityA.refreshData = true;
Intent myIntent = new Intent(v.getContext(), ActivityT.class);
startActivityForResult(myIntent, 0);

我很想知道,是否有更好的办法做这种事情!

问题回答

我最后大力迫使这一问题,并抄录了塔霍斯特、塔博特和塔瓦德戈特法典,使其符合我解决这一问题的需要。 它不是我骄傲的事情,而是trick。

由于我为方便做其他事情做了一些小小小的 other子,这也显得有些有用。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签