简体   繁体   English

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

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

I have an android appand I want to store an android Intent in the database as a blob field.我有一个 android 应用程序,我想将 android Intent 作为 blob 字段存储在数据库中。 I know the basics of storing and retrieving data of TEXT, INTEGER, etc, standards types in SQLite as my app already does all of that.我知道在 SQLite 中存储和检索 TEXT、INTEGER 等标准类型的数据的基础知识,因为我的应用程序已经完成了所有这些。 I am not familiar with storing and retrieving blobs.我不熟悉存储和检索 blob。 I am presuming the blob is the best way, versus storing as a string and parsing back to and Intent.我假设 blob 是最好的方法,而不是存储为字符串并解析回 Intent。 Maybe that is not a correct assumption though.也许这不是一个正确的假设。 The intents can be a package name, URI, may have extras, etc. That is why I would like to store/retrieve the whole intent and not just store parts.意图可以是 package 名称、URI、可能有额外内容等。这就是为什么我想存储/检索整个意图而不仅仅是存储部分。

You can simply store the intent in a String way:您可以简单地以字符串方式存储意图:

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

Later you can restore the Intent:稍后您可以恢复 Intent:

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

Use the Parcelable interface with the Intent:将 Parcelable 接口与 Intent 一起使用:

Parcel  parcel;  
myIntent.writeToParcel(parcel);

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

Reverse the process to get it out.反转过程以将其取出。

If you prefer text, then you could consider using json.如果您更喜欢文字,那么您可以考虑使用 json。

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

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