2

i am having many activities like settings,game,home etc.i want to accept some values from user in settings page.when i click on the done button all these values have to b stored in variables.at the same time i am going back to home page.from there i am going to game class.in that i want to get the previously stored values from settings page.i know using bundle is better to do this task.but i dnt knw how to use that for more than 1 value.plz help me.given below is my code snippet

done.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                namevalue=name.getText().toString();
                overvalue=over.getText().toString();
                audiostatus=audio.getText().toString();
                Intent intent=new Intent(Settings.this,home.class);
                 Bundle bundle = new Bundle();   
                 bundle.putString( "namevalue",namevalue);        
                 intent.putExtras(bundle);   
                 startActivity(intent);                 
                }
            });
ingsaurabh
  • 15,249
  • 7
  • 52
  • 81
star angel
  • 520
  • 2
  • 7
  • 14

4 Answers4

4

Use this code to send multiple data from one activity to other

done.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                namevalue=name.getText().toString();
                overvalue=over.getText().toString();
                audiostatus=audio.getText().toString();
                Intent intent=new Intent(Settings.this,home.class);
                 Bundle bundle = new Bundle();   
                 bundle.putString( "namevalue",namevalue);  
                 bundle.putString("overvalue",overvaluse);
                 bundle.putInt("value",variablename);
                 intent.putExtras(bundle);   
                 startActivity(intent);                 
                }
            });
NoNaMe
  • 6,020
  • 30
  • 82
  • 110
samer
  • 41
  • 1
2

You should use Intent itself to pass data from One Activity to another. Use intent.putExtra("NAME", data); you could refer to this thread

Community
  • 1
  • 1
Adil Soomro
  • 37,609
  • 9
  • 103
  • 153
2

PS: Why not use SharedPrefernces to share your settings data anywhere within your application?

Ramya K Sharma
  • 743
  • 8
  • 16
1

bundle.putStringArray allows you to put multiple string values. Check for other put*Array.

Ramya K Sharma
  • 743
  • 8
  • 16