简体   繁体   中英

Android serialize a 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 new PendingIntent later on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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