繁体   English   中英

使用 android 将 Intent 存储在 SQLite 数据库中

[英]Storing in Intent in an SQLite database with android

我有一个 android 应用程序,我想将 android Intent 作为 blob 字段存储在数据库中。 我知道在 SQLite 中存储和检索 TEXT、INTEGER 等标准类型的数据的基础知识,因为我的应用程序已经完成了所有这些。 我不熟悉存储和检索 blob。 我假设 blob 是最好的方法,而不是存储为字符串并解析回 Intent。 也许这不是一个正确的假设。 意图可以是 package 名称、URI、可能有额外内容等。这就是为什么我想存储/检索整个意图而不仅仅是存储部分。

您可以简单地以字符串方式存储意图:

String intentDescription = intent.toUri(0);
//Save the intent string into your database

稍后您可以恢复 Intent:

String intentDescription = cursor.getString(intentIndex);    
Intent intent = Intent.parseUri(intentDescription, 0);

将 Parcelable 接口与 Intent 一起使用:

Parcel  parcel;  
myIntent.writeToParcel(parcel);

ContentValues values = new ContentValues();  
values.put(MyField, parcel.createByteArray());  
getContentResolver().insert(MyBaseColumn.MyTable.CONTENT_URI, values);

反转过程以将其取出。

如果您更喜欢文字,那么您可以考虑使用 json。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM