通过存储访问框架传递额外数据
Passing extra data through the Storage Access Framework
我有一个 ListView
,通过单击 ListView 的一个项目,我调用了存储访问框架 (SAF)。
就在开始 SAF 之前,我想像这样传递 ListView
的位置:
intent.putExtra("Position", position);
startActivityForResult(intent, WRITE_REQUEST_CODE);
但是如何在 onActivityResult()
方法中返回位置以便我知道单击了哪个项目?
我尝试了这些行,但没有成功:
Bundle extras = resultData.getExtras();
Integer i = getIntent().getIntExtra("routeDataPosition", 42);
Integer i2 = resultData.getIntExtra("routeDataPosition", 42);
Just before starting the SAF, I want to pass the position of the ListView like this:
那是行不通的。你不能强迫其他应用进入另一个应用程序,你也不能强迫另一个应用程序 return 这些额外功能。
But how do I get the position back in the onActivityResult() method so I know which item is clicked?
您可以将其存储在 activity、片段或视图模型的字段中。
如果您想详细说明,可以根据职位使用不同的请求代码。因此,使用 WRITE_REQUEST_CODE + position
而不是 WRITE_REQUEST_CODE
。您需要在 onActivityResult()
中有智慧才能从结果代码中取回位置(例如,position = resultCode - WRITE_REQUEST_CODE
)。
我有一个 ListView
,通过单击 ListView 的一个项目,我调用了存储访问框架 (SAF)。
就在开始 SAF 之前,我想像这样传递 ListView
的位置:
intent.putExtra("Position", position);
startActivityForResult(intent, WRITE_REQUEST_CODE);
但是如何在 onActivityResult()
方法中返回位置以便我知道单击了哪个项目?
我尝试了这些行,但没有成功:
Bundle extras = resultData.getExtras();
Integer i = getIntent().getIntExtra("routeDataPosition", 42);
Integer i2 = resultData.getIntExtra("routeDataPosition", 42);
Just before starting the SAF, I want to pass the position of the ListView like this:
那是行不通的。你不能强迫其他应用进入另一个应用程序,你也不能强迫另一个应用程序 return 这些额外功能。
But how do I get the position back in the onActivityResult() method so I know which item is clicked?
您可以将其存储在 activity、片段或视图模型的字段中。
如果您想详细说明,可以根据职位使用不同的请求代码。因此,使用 WRITE_REQUEST_CODE + position
而不是 WRITE_REQUEST_CODE
。您需要在 onActivityResult()
中有智慧才能从结果代码中取回位置(例如,position = resultCode - WRITE_REQUEST_CODE
)。