【问题标题】:Android - Passing integer value from One Activity to Android Native implicit intent and recive to another activityAndroid - 将整数值从一个 Activity 传递到 Android Native 隐式意图并接收到另一个 Activity
【发布时间】:2017-06-26 12:07:07
【问题描述】:

我有一个活动名称 AlbumPicker。 在那个活动中,我在按钮单击时调用下面的代码。

Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.putExtra("Example", 40);
((Activity) _ctx).startActivityForResult(
                        Intent.createChooser(intent, "Select Picture"),
                        returnCode); 

现在画廊将打开。

然后我会选择一张图片。

然后下面的方法将被调用 我想要下面方法中的示例值

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   int example = data.getIntegerExtra("Example);
}

但是这段代码失败了。 我总是收到 0

请帮忙

【问题讨论】:

标签: android android-intent android-gallery android-implicit-intent


【解决方案1】:

您无法控制 Gallery Activity 返回的数据,它只是返回自己的结果意图,因此您的额外意图会丢失。 你应该使用另一种方法来获取价值,也许你可以使用这样的东西:

final int yourReturnCode = 3040;
final int yourExampleValue = 40;
Intent intent = new Intent(Intent.ACTION_PICK, 
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
((Activity) _ctx).startActivityForResult(
                    Intent.createChooser(intent, "Select Picture"),
                    yourReturnCode);





protected void onActivityResult(int requestCode, int resultCode, Intent 
              data) {
         int yourValue = 0;
       if (resultCode == yourReturnCode) {
             yourValue = yourExampleValue;
         }
    }

【讨论】:

  • 谢谢@diegoveloper。让我试试这个
猜你喜欢
  • 2017-04-05
  • 2016-01-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-08
  • 1970-01-01
  • 1970-01-01
  • 2020-10-19
相关资源
最近更新 更多