问题标签 [android-bundle]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
3206 浏览

java - 解析捆绑数据

我在我的应用程序中使用 GCM,我正在从服务器向客户端发送一些数据。数据是这样的:

我在我的 GcmListener 中获取这些数据:

如何将此数据解析为对象?我找不到这么多信息,我搜索了好几个小时。

谢谢。


解决了。这篇文章有所帮助,我在服务器中使用了 JSON.stringfiy。

http://www.javacodegeeks.com/2011/01/android-json-parsing-gson-tutorial.html

0 投票
2 回答
17080 浏览

android - 从 BroadcastReceiver 类发送 Intent 到当前正在运行的活动

我有一个扩展类BroadcastReceiver。收到短信后,我想将信息传递给我的主要活动类以在框中显示文本(附加,如果已经存在文本)。

MainActivity.java

我只有一个活动课(MainActivity.java)。但是,当我这样做时,我得到一个异常无法暂停活动。

0 投票
1 回答
85 浏览

android - 在 Android 中通过捆绑/附加功能传递 PIN 是否安全?

我需要让用户输入他的应用密码并再次输入以确认该密码。我不会将该引脚保存在设备上,并会在收到后立即将其发送到服务器上。

在实施确认屏幕时,我想到了这个问题。

在有根的android设备中,如果我们使用bundle在活动之间传递数据,那么其他一些应用程序可以找出使用bundle传递的值吗?

PS:我们正在使用自定义键盘进行输入(pin)。

0 投票
0 回答
194 浏览

android - 如何使用捆绑包中的数据将项目添加到网格视图

我正在使用本教程制作gridview: https ://developer.android.com/guide/topics/ui/layout/gridview.html

我已将 mThumbIds 从arrayto更改为List<Integer>,我正在尝试使用通过 Bundle 从 MainActivity 到达 dataGridFragment 的数据对其进行初始化,但它不起作用。如果我手动添加元素,它会起作用。我认为那个捆绑包来得太晚了,但不知道如何同步它。

0 投票
2 回答
8036 浏览

java - android.os.Bundle 中 getInt(string key) 返回的整数是多少?

我阅读了有关 getInt() 方法的文档:

public int getInt(字符串键)

返回与给定键关联的值,如果给定键不存在所需类型的映射,则返回 0。

参数:

键入一个字符串

返回:

一个 int 值

但我不知道它到底返回了什么。

那个IDkey在R.java中还是没有别的???

0 投票
2 回答
3245 浏览

android - 无法从活动中获取片段中的捆绑参数

作为 android 开发人员(目前是 PHP 程序员),我是一个非常新的人。我正在尝试通过遵循 google 开发人员和其他网站的各种教程来学习 android。

我的问题是我无法在我的活动中设置的片段中获取捆绑参数。

这是我的 HomeActivity 的方法:

这是我的 FragmentImageList 片段:

我的错误日志

字符串 strtext=getArguments().getString("test_string"); 不工作。我也试过 Bundle bundle = this.getArguments(); Log.d(TAG, bundle.getString("test_string")); 但它也不起作用。但是,如果我评论这些捆绑行,那么应用程序运行良好且没有错误。这个“test_string”只是我试图让它工作的一个测试参数。所以,我想知道我犯了什么错误导致我出现这个错误

编辑:我正在尝试在我的 Nexus 5 android 版本 5.1.1 中运行这个应用程序

0 投票
0 回答
267 浏览

android - android在恢复活动很长时间后不幸停止了

我正在创建一个简单的应用程序。在使用我的应用程序时,当我单击主页并转到另一个应用程序并工作一段时间(例如 10 到 15 分钟)时。

当我回到我的应用程序时,它会显示“不幸的是应用程序停止”消息。然后应用程序突然关闭。

像这样抛出异常:

0 投票
1 回答
909 浏览

android-fragments - Android Fragment 实例变量与 Bundle 参数?

Android Fragment 实例变量和捆绑参数有什么区别?什么时候用什么?

0 投票
2 回答
254 浏览

android - 从意图数据中获取短信地址

我需要从不同类型的意图中检索电话号码。案例的意图如下:

或者:

当我开始新活动时,我会得到我的捆绑附加服务:

具体来说,对于第一种情况,意图显式绑定一个额外的密钥,"address"我这样做:

但是我在尝试smsto:在第二个意图案例之后检索值时遇到了一些麻烦。

我已经尝试通过以下方式迭代捆绑附加功能:

}

但如果附加项是空的,这给我一个 NPE。

由于谷歌本身缺乏文档,我找不到任何东西,所以任何答案都会非常有帮助!提前致谢。

0 投票
1 回答
599 浏览

java - 存储 ArrayList in an Bundle for use by a Fragment

My application has a view pager including three fragments. These are managed by a FragmentPagerAdapter.

protected void onCreate(Bundle savedInstanceSta

My application has a view pager including three fragments. These are managed by a FragmentPagerAdapter.

Things start to get complicated when all of these Fragments contain a RecyclerView that can be updated.

To correctly pass data to the Fragments, I'm using the newInstance method shown below:

I then have another method inside InformationFragment to update the arguments when required:

Data that can be used to populate the RecyclerView needs to be of multiple types (some android, some custom). Therefore, I have ArrayList<Object> items; containing all my objects.

My question is, what is the best way to store this ArrayList in a bundle so it can be used by a fragment?

I am able to do the following, but it feels dirty:

and then retrieve by:

Or is there a better approach?


I think the problem is that

is a method call and the output (and it's attributes) can't change by assignment in the way you've done. That is, the line

has no effect. You could do something like

Not sure this will solve the problem as I don't know the context but it will print what you want in the example