can any one guide me what mistake am i doing in this code??? it not seems to be working..
i have two activies
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = new Intent(DataPass开发者_如何学Going.this, DataPassing2.class);
Bundle b = new Bundle();
b.putInt("key", 1123);
intent.putExtras(b);
startActivity(intent);
finish();
}
and in second activity i have written
public void onCreate(Bundle savedInstanceState) {
Bundle b = getIntent().getExtras();
int value = b.getInt("key", 0);
Toast.makeText(this, value, Toast.LENGTH_SHORT).show();
}
but the code is giving me error i dont know why.. i have added second activity to manifest file.. please guide what mistake i am doing ???
any help would be appriciated..
Can you debug the code, or perhaps include some try/catch-blocks, to try and detect where the error is happening, and what the error message is?
Other than that, try doing it this way instead:
Intent intent = new Intent(DataPassing.this, DataPassing2.class);
intent.putExtra("key", 1123);
startActivity(intent);
... and still fetch the bundle in DataPassing2
as you have been before. I don't know if it'll help, because I don't know much about what your error is, but it might.
Try this one may be it work.
public void onCreate(Bundle savedInstanceState) {
Bundle b = getIntent().getExtras();
int value = b.getInt("key");
Toast.makeText(this, value, Toast.LENGTH_SHORT).show();
}
精彩评论