Pass values between activitys inner Tab

Put your problem here if it does not fit any of the other categories.

Pass values between activitys inner Tab

Postby hell0_android » Sun Feb 19, 2012 3:52 am

Hi all
Now I have a tabactivty is class A contain two tabs: tab1 have class B,tab2 have class C...
When run project tabactivity is display at tab1...In class B , i have a button1 to go to the class class C i have a edittext and a button2...I want enter any text in edittext and click button to pass them to class B...
I have try any way:
In classB :
when click button1 I setcurrenttab(1) to go class C and in onCreate

Intent myIntent = new Intent();
myIntent = this.getIntent();
String value_receive = myIntent.getString("stringtext");

In class C:
when click button2 I set curretTab(0) to go class B and method onPaused of class C
public void onStop(){
Intent myIntent = new Intent();
myIntent.putExtra("stringtext", edittext.getText().toString());

but when i run project button1 in class B not display text received from class C....

Can you help me to pass value between activity in tab....Thank for regard !
Posts: 9
Joined: Wed Sep 14, 2011 4:39 pm


Re: Pass values between activitys inner Tab

Postby Phyll » Sun Feb 19, 2012 1:53 pm

Hi hello_android,

Here is a way to make variables that you don't need to "pass" from one activity to another in your app.

Create a class like this.

Code: Select all
public class GlobalVars extends Application {
    public String globalText = "Default";

Add this to your manifest in the application name: android:name=".GlobalVars" like this:

Code: Select all
Just an example

   <application android:name=".GlobalVars"



Then add it to your activities (for each tab) like this:

Code: Select all
public class MyActivity extends Activity {

   private GlobalVars globalVars = null;   //Global context for applicaiton variables
                private String localText;

    public void onCreate(Bundle icicle) {
        //get the application context and store it as our handle to the global variables
        globalVars = ((GlobalVars)getApplicationContext());
        localText = globalVars.globalText;

You can find more about application global variables on the internet. There are some obscure drawbacks. I also noticed that tabactivity has been deprecated so you may want to look into that. Global variables still cure a lot of problems sharing variables.

Hope this helps.

Master Developer
Master Developer
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 13 guests