Apart from the options below (and the other options, such as Web storage - discussed here, or JSON options), there is no way to send data from one Activity
to another. You should either reconsider how you are doing what you are trying to do, or consider using a different Driver
.
If the code is open source or open licensed, you may consider hacking in Serializable
or Parcelable
by extracting the source and modifying it to fit your needs. More on decompiling Android
source is available here.
There are several methods you can use for sharing content between two Activities in different projects:
1. SharedPreferences
, SQLite
, Serialization
, or Content Providers
. These will all require you to break down your Driver Object into simple types. More on storage can be found in the docs.
2. Parcelable
s can be shared via Intent
between Activities.
There are several methods you can use for sharing content between two Activities in the same project:
1. You can use SharedPreferences
, SQLite
, or Serialization
. More on storage can be found in the docs.
2. You can set it to a static variable. For example, have a Store
class where you save static variables:
public class Store {
/** provides static reference to the driver */
public static Object driver;
}
Then to set from anywhere, just do:
Store.driver = myDriver;
and to get from anywhere, just do:
Object driver = Store.driver;
3. Create a custom Application
class and set this in your Android Manifest. This application can store the driver, and doesn't necessarily have to be static. More on this can be found at Extending Application to share variables globally.
4. The third option is to create a singleton accessor to your Activity
. So, in your activity that has the driver referenced, add the following class variable:
private static MyActivity self;//replace MyActivity with the name of your class.
Then, add the getter:
public static MyActivity sharedMyActivity() {
return self;
}
Finally, add this line in onCreate
(after the call to super.onCreate(...)
):
self = this;
Now to access your driver (we'll say it has a getter), just call this from anywhere:
Object driver = MyActivity.sharedMyActivity().getDriver();
As for part two of your question - if you are attempting to read from and write to a hardware device in an Activity
that does not provide USB
permissions, this will not work.