简体   繁体   中英

how to putExtra and intent class together with one intent

i want use one intent that intent class with put extra

 case R.id.button_6:
    {
        Intent intent = new Intent(this, class_);
        this.startActivity(intent);

        Intent i = new Intent(getApplicationContext(), class_.class);
        i.putExtra("data",data);
        startActivity(i);
    }

You don't need all that stuff, just:

Intent i = new Intent(getApplicationContext(), class_.class);
i.putExtra("data", data);
startActivity(i);

You create the intent with class_ and pass data as an extra.

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Class.getName()' on a null object reference

public class class_ extends Activity  {

                ListAdapter adapter=null;
                ListView lst;
                ArrayList<HashMap<String, String>> data= new ArrayList<HashMap<String, String>>();;

                protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.class_);
                  lst=(ListView) findViewById(R.id.list);

                      Intent i = getIntent();



                        data= (ArrayList<HashMap<String, String>>) i.getSerializableExtra("data");
                        if(data!=null){

                        adapter = new list_view(this, data);

                      lst.setAdapter(adapter);
                        }
                        }
            }
  Intent i = new Intent(this,class_.class);
  i.putExtra("data",data);
  startActivity(i);

And get it in another activity like this..

  String data = getIntent().getExtras().getString("data");

It is for string you can define type which you are sending from your activity

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM