开发者

How to pass value from page 1 to page 3?

I have 3 pages in my app, and it have to go to page 1 -> 2 -> 3 as sequence

and I want to send value from page 1 to page 3 how to send it without through page 2

How to code it?

////edit

I use

Intent toPage3 = new Intent(getParent(), page3.class);
Bundle dataBundle = new Bundle();
dataBundle.putString("value",value);
toPage3.putExtras(dataBundle);

Intent toPage2 = new Intent(getParent(), page2.class);
TabGroupActivity parentActivity = (TabGroupActivity)getParent();
parentActivity.startChildActivity("CategoriesTabActivity", toPage2);

but page 3 can't recieve the value

Wh开发者_如何学Goat should I do?


You can do this with Intents, they can act as a message transport between activities.

Intent

Intent and Filters


use intent.putextra(). you will not need to go via second page. Learn from developer.android.com about this.

use this on sending activity

     Intent bin= new Intent(this,B.class);
        bin.putExtra("a","b");
        bin.putExtra("c",12);

and this on receiving

    Intent call=getIntent();
               String s=call.getStringExtra("a");
               int d=call.getIntExtra("c", 0);


Android Activities are based on Intents so you move from Activity X to Activity Y by sending an intent from x to y. that have some extras.

So you can just do this by calling

Intent myIntent = new Intent(this, myActiviyY.class);
myIntent.putExtra(String,String);

Read more about Intents and Activities


the page3 didn't receive the value because you past it from the page2 , but in your code, you pass to the page3 from the page2 , so you should pass the value from page1 to page 2 , and then you can pass it the page 3 , i dont think that is possible to pass it wthout page2 ,

the second thing :

you dont have :parentActivity.startChildActivity("CategoriesTabActivity", toPage3); launched from your page1 , so your intent toPage3 is unuseful , you should pass through page2 ,

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜