gpt4 book ai didi

android - 为什么 startActivityForResult 不起作用?

转载 作者:行者123 更新时间:2023-11-29 15:45:15 26 4
gpt4 key购买 nike

我正在使用 startActivityForResult 将值从 Activity B 返回到 Activity A。但是当点击 B 中的保存 按钮 时,它不会返回到 ActivityA。有人可以帮我解决问题吗?

Activity 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");

}
});

Activity 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)
{

}
}

最佳答案

在 Activity B 中调用 setResult 后,您没有完成 Activity。确保调用 finish()

关于android - 为什么 startActivityForResult 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33968436/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com