android activities
i have 2 activities. 1-Messaging 2-fileBrowser from MESSAGING onButtonClick i call the FILEBROWSER activity. in the FILEBROWSER activity i take the path of the selected file a开发者_如何学编程nd put it to a interface and then call the MESSAGING activity again like this :
Intent i = new Intent(FileBrowser.this, Messaging.class);
i.putExtra(FriendInfo.P, path);
System.out.println("path at fb" + path);
startActivity(i);
this.finish();
now when i m returned back to the MESSAGING activity everything over here is null. all the variables and everything and if i call some other methods, the arguments i pass are also null. what do i do ?
when first time you move Messaging to FileBrowser
instead of stariActivity()
you can use StartActivityForResult()
method and at Activity FileBrowser just set result and put data in bundle then you can use this result in Messaging Activity's
onActivityResult().
Then your Messaging Activity's all variable remain same. No NULL value.
EDIT: In MessagingActivity
Intent intent = new Intent(Messaging.this, FileExplorer.class);
intent.putExtra("Key", value);
startActivityForResult(intent, RESULT_OK);
and also make this method
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
//getting value from FileExplorer activity here
}
}
Try to start your Intent with StartActivityForResult(Intent intent)
精彩评论