Android的序列化的PendingIntent [英] Android serialize a PendingIntent
问题描述
我知道一个的PendingIntent没有实现Serielizeable接口。但是,如果我创建一个POJO,并添加意图作为我对象的成员,并让那POJO实现可序列化,将这项工作?
这是我所想的:
意向意图=新意图(这一点,someClass.class);
PI的PendingIntent = PendingIntent.getActivity(这一点,0,意向,0);POJO myPOJO =新POJO();
myPojo.setIntent(PI);
...
序列化POJO等等,如上所述。这会否POJO仍然是可序列化,和反序列化后,我将能够获取与myPOJO.getIntent中的PendingIntent(); ?
如果很明显对不起。感谢您的任何帮助。
马库斯
但是,如果我创建一个POJO,并添加意图作为我对象的成员,并让那POJO实现可序列化,将这项工作?
块引用>没有。
我将能够获取与myPOJO.getIntent中的PendingIntent(); ?
块引用>没有。 A
的PendingIntent
无法生存的运行OS之外。在这种情况下,假设你的code段酷似你的实际使用情况,您不必坚持了
的PendingIntent
;相反,坚持,让你做的事一个新的的PendingIntent
以后。I know that a PendingIntent doesn't implement the Serielizeable interface. But if I create a POJO and add that intent as a member of my object, and letting that POJO implement serializeable, will that work?
This is what I think:
Intent intent = new Intent(this, someClass.class); PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0); POJO myPOJO = new POJO(); myPojo.setIntent(pi); ...
serialize the POJO etc, as explained above. Will that POJO still be serializeable, and after deserialization, will I be able to fetch the PendingIntent with myPOJO.getIntent(); ?
Sorry if it's obvious. thankful for any help.
Marcus
解决方案But if I create a POJO and add that intent as a member of my object, and letting that POJO implement serializeable, will that work?
No.
will I be able to fetch the PendingIntent with myPOJO.getIntent(); ?
No. A
PendingIntent
cannot survive outside of the running OS.In this case, assuming that your code snippet resembles your actual use case, you do not need to persist the
PendingIntent
; instead, persist the things that allow you to make a newPendingIntent
later on.这篇关于Android的序列化的PendingIntent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!