我使用startActivityForResult
将值从活动B返回到行动A。但是,当单击在B中保存button
时,它不会返回到活动A。有人能帮我解决这个问题吗?
活动B
save.setOnClickListener(new View.OnClickListener()
{ // return values to previous activity
@Override
public void onClick(View v)
{
Intent returnIntent=new Intent();
Project=project.getSelectedItem().toString();
Description=description.getText().toString();
progress=seekBar.getProgress();
returnIntent.putExtra("Project",Project);
returnIntent.putExtra("Description", Description);
returnIntent.putExtra("progress",progress);
returnIntent.putExtra("TimeIn", TimeIn);
returnIntent.putExtra("TimeOut",TimeOut);
setResult(Activity.RESULT_OK,returnIntent);
Log.e("d","d");
}
});
活动A
public static final int PROJECT_REQUEST_CODE = 1;
public static final int CAMERA_REQUEST_CODE = 2;
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.addDetails:
View menuItemView = findViewById(R.id.addDetails);
PopupMenu po = new PopupMenu(this, menuItemView); //for drop-down menu
po.getMenuInflater().inflate(R.menu.popup_details, po.getMenu());
po.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(getApplication(), "You Clicked : " + item.getTitle(), Toast.LENGTH_SHORT).show();
if ("Add Work Details".equals(item.getTitle())) {
Intent intent = new Intent(getApplication(), Add_Details_Information.class); // go to B
startActivityForResult(intent, PROJECT_REQUEST_CODE);
}
return true;
}
});
po.show(); //showing popup menu
}
return super.onOptionsItemSelected(item);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { // receive from B
if(requestCode==PROJECT_REQUEST_CODE)
{
ReceiveProject = data.getStringExtra("Project");
ReceiveDescription = data.getStringExtra("Description");
ReceiveProgress = data.getStringExtra("progress");
ReceiveTimeIn = data.getStringExtra("TimeIn");
ReceiveTimeOut = data.getStringExtra("TimeOut");
ArrayList<SearchResults> searchResults = GetSearchResults(weather, date, status, ReceiveTimeIn, ReceiveTimeOut);
listview.setAdapter(new MyCustomBaseAdapter(this,searchResults));
}
else if(requestCode==CAMERA_REQUEST_CODE)
{
}
}
在活动B中调用setResult
之后,您没有完成活动。请确保调用finish()
。