首页 > 代码库 > Android——使用 Intent传递类

Android——使用 Intent传递类

  定义要传递的类事,必须加上

public class Movie implements Serializable
{

}

传入类:

public void onItemClick(AdapterView<?> parent,
                                    View view, int position, long id)
      {
          Movie movie= movieList.get(position);
          Intent intent = new Intent(MovieActivity.this, EditMovie.class);
          Bundle bundle = new Bundle();
          bundle.putSerializable("movie", movie);
          intent.putExtras(bundle);
          startActivity(intent);
      }

接受类:

Movie movie = (Movie) getIntent().getSerializableExtra("movie");
String name = movie.getName();
String desc = movie.getDesc();
editText1.setText(name);
editText2.setText(desc);

 

Android——使用 Intent传递类