How to pass one computed variable in multiple activity

how to access variables from one activity to another in android
how to pass data from one activity to another in android using intent
how to send data from one activity to another in android without intent
how to access variable from another activity in android
how to pass data from one activity to another in android example
how to send data from one activity to another in android using bundle
how to pass edittext value from one activity to another activity in android
how to pass values from one activity to another in android

I just figured out how to use intent to pass variables to other activity ,but I found out that it has a limit , it can only pass one variable to one activity . I want to know how to share the variable in multiple activity like I have this variable in activity 1 and I want to use it in activity 2 and activity 3.

this is my activity 1 , the variable I want to use in other activity is this (double ans=(90+4.8*nh+13.4*nw-5.7*na);) I figured out how to pass it to activity 2 but I can't pass it to activity 3. Is there an easy way to pass the variable in multiple activity , because I'm kinda new to Android and OOP there's a lot of stuff I don't really get just from searching. Thank you so much!

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_male);

    age =(TextView)findViewById(R.id.age);
    height=(TextView)findViewById(R.id.heigth);
    weight =(TextView)findViewById(R.id.weigth);
    result =(TextView)findViewById(R.id.result);

    eage=(EditText)findViewById(R.id.eage);
    eheight=(EditText)findViewById(R.id.eheight);
    eweight=(EditText)findViewById(R.id.eweight);


    calculate=(Button)findViewById(R.id.calculate);
    back =(Button)findViewById(R.id.back);
    next =(Button)findViewById(R.id.next);



    calculate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            double na=Double.parseDouble(eage.getText().toString());
            double nh=Double.parseDouble(eheight.getText().toString());
            double nw=Double.parseDouble(eweight.getText().toString());
            double ans=(90+4.8*nh+13.4*nw-5.7*na);
            result.setText("Your BMR is "+ans);



        }
    });

    back.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i=new Intent(MALE.this,MainActivity.class);
            startActivity(i);
        }
    });

    next.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i = new Intent(MALE.this, MALERUN.class);
            double na=Double.parseDouble(eage.getText().toString());
            double nh=Double.parseDouble(eheight.getText().toString());
            double nw=Double.parseDouble(eweight.getText().toString());
            double ans=(90+4.8*nh+13.4*nw-5.7*na);
            result.setText("Your BMR is "+ans);
            i.putExtra("answer",ans);
            i.putExtra("age",na);
            i.putExtra("height",nh);
            i.putExtra("weight",nw);
            startActivity(i);
        }
    });



}

Using SharedPreferences you can get it.here is examples

    next.setOnClickListener{

        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putString("answer",ans);
        editor.putString("age",""+na);
        editor.putString("height",""+nh);
        editor.putString("weight",""+nw);
        editor.commit();

        Intent i=new Intent(MALE.this,MainActivity.class);
        startActivity(i);
    }

Any Another Activity you can get it below

      @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        SharedPreferences sharedPref = 
        PreferenceManager.getDefaultSharedPreferences(this);  
        String answer = sharedPref.getString("answer",null);
        String age = sharedPref.getString("age",null);
        Log.e("resultsss",""+answer + " age : "+age);

}

Solution 2:

Either you have to use Sqlite database

suggestion: if you have very less fields better to use SharedPreferences if you have little hug data better go with Sqlite database

Communicating with Objects and instance variables outside its parent class has always while working on a multiple activity project i decided to write on the means i First in the SecondActivity we have to create an intent that will get the data  Using Bundle you can pass values from one Activity to another. To send multiple values, use any model/pojo class to store those values and pass that model as parcelable/serializable through bundle.


Use SingleTon Pattern.

public class SingletonClass {

    private double yourValue;
    private static SingletonClass sSoleInstance;

    private SingletonClass() {
    } // private constructor.

    public static SingletonClass getInstance() {
        if (sSoleInstance == null) { 
            sSoleInstance = new SingletonClass();
        }

        return sSoleInstance;
    }

    public void setValue(double val) {
        yourValue = val;
    }

    public double getValue() {
        return yourValue;
    }
    }

Set Variable from Activity1

    SingletonClass.getInstance().setValue(yourValue);

Now you can access this value across application.

    SingletonClass.getInstance().getValue();

For more details click here

For this, we need to be able to pass the values input by the user in the second View to the activity managing the first View so that we can compute the monthly and total There are several ways that we can pass data from one activity to another, We declare a public static variable of type Mortgage in the MainActivity class  The main logic used here is very simple, wherein you just need to use the putExtra Method to pass the data across multiple program screens. The putExtra method accepts many kinds of data, such as String, int, float, byte etc..


You can declare a varible :

public class MainActivity extends AppCompatActivity {

// Like below
    public static double ans;

@Override
protected void onCreate(Bundle savedInstanceState) {
...
   }
}

And call it from everywhere like this:

MainActivity.ans;

You can declare a different variable anytime you want and it will change in every Activity.

just do this :

MainActivity.ans = 123.123;

may participate mostly in resource-based activities while others may We computed participation indices by averaging a person's total participation level for orientations” presented here are based on an a priori grouping of activities. is hierarchical (it makes multiple passes and eventually clusters all variables), we can  Hello Friends! In this android tutorial, I'm showing you how to make an android app that pass edit text value from one activity to another activity. Thanks for watching this video. If you like


may participate mostly in resource - based activities while others may We computed participation indices by averaging a person ' s total these activities were largely independent of one another in terms of participation . Because the routine is hierarchical ( it makes multiple passes and eventually clusters all variables )  How to Pass Data from One Activity to Another in Android. Method 1: Using Intent. We can send data while calling one activity from another activity using intent. All we have to do is add the data to Intent object using putExtra() method. The data is passed in key value pair.


The backward pass generates a variable defined as T(L) and it is formatted on the node (8) and insert the same time as calculated for the forward pass—21 in the sample case. Node 6 would be calculated as 16 - 4 (for activity G) or 12. you encounter a node that has multiple paths coming back into it, such as node 3. In this video tutorial, you can check how to pass values from one android activity to another activity using bundle class. The Activity one contains a listview, when any listitem is clicked, the


Pass data to an activity from MainActivity: Intent intent = new Intent(MainActivity.​this Duration: 28:21 Posted: Feb 16, 2014 how to pass url from one activity to another activity, kindly please help me.. here by i'll add the snippet, when i run the program, activity is changing but page is blank. first activity, String url = result[1].toLowerCase(); Intent i = new Intent(getApplicationContext(), choice.class); i.putExtra("url",url); startActivity(i); break; second