Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How do I access variable value in another activity. In my example I have a string variable item which value is spinner selected value. How can I access this variable in another activity without using Intent?

  public class LoginScreen extends Activity {

      Spinner sp;
String item;


      Spinner sp = (Spinner) findViewById(R.id.lgnspinner);

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
            this, R.array.network_array,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    sp.setAdapter(adapter);

    sp.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> parent, View view,
                int position, long id) {
            item = (String) parent.getItemAtPosition(position);



        public class AgAppMenu extends Activity {
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
209 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can declare them as static variables and then in your other class you may access them like Activity1.stringName.

public static String stringName; 

stringName = .. // value from Spinner

Then, in all the other Activities, you can access them as YourMainActivty.stringName.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...