Android: pass object without serialization -


i'm using library usb communication written else. i'm using 1 activity find correct usb device , make appropriate driver object , want use driver in activity (the why of bit complicated).

unfortunately, driver object doesn't implement parcelable or serializable i'm not sure how this. have 2 questions

1) options there passing driver object between activities?

2) if succeed in question 1, run problems because receiving activity hasn't been given explicit permission use usb object?

apart options below (and other options, such web storage - discussed here, or json options), there no way send data 1 activity another. should either reconsider how doing trying do, or consider using different driver.

if code open source or open licensed, may consider hacking in serializable or parcelable extracting source , modifying fit needs. more on decompiling android source available here.

there several methods can use sharing content between 2 activities in different projects:

1. sharedpreferences, sqlite, serialization, or content providers. these require break down driver object simple types. more on storage can found in docs.


2. parcelables can shared via intent between activities.

there several methods can use sharing content between 2 activities in same project:

1. can use sharedpreferences, sqlite, or serialization. more on storage can found in docs.


2. can set static variable. example, have store class save static variables:

public class store {     /** provides static reference driver */     public static object driver; } 

then set anywhere, do:

store.driver = mydriver; 

and anywhere, do:

object driver = store.driver; 

3. create custom application class , set in android manifest. application can store driver, , doesn't have static. more on can found @ extending application share variables globally.


4. third option create singleton accessor activity. so, in activity has driver referenced, add following class variable:

private static myactivity self;//replace myactivity name of class. 

then, add getter:

public static myactivity sharedmyactivity() {     return self; } 

finally, add line in oncreate (after call super.oncreate(...)):

self = this; 

now access driver (we'll has getter), call anywhere:

object driver = myactivity.sharedmyactivity().getdriver(); 

as part 2 of question - if attempting read , write hardware device in activity not provide usb permissions, not work.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -