我使用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)
{
}
}
答案 0 :(得分:4)
在活动B中致电setResult
后,您仍未完成活动。请务必致电finish()
。