Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Apart from the options below (and the other options, such as Web storage - discussed <a href="http://developer.android.com/guide/topics/data/data-storage.html" rel="nofollow noreferrer">here</a>, or <a href="http://developer.android.com/reference/java/io/Serializable.html" rel="nofollow noreferrer">JSON options</a>), there is no way to send data from one <code>Activity</code> to another. You should either reconsider how you are doing what you are trying to do, or consider using a different <code>Driver</code>. </p> <p>If the code is open source or open licensed, you may consider hacking in <code>Serializable</code> or <code>Parcelable</code> by extracting the source and modifying it to fit your needs. More on decompiling <code>Android</code> source is available <a href="https://stackoverflow.com/questions/1249973/decompiling-dex-into-java-sourcecode">here</a>.</p> <h3>There are several methods you can use for sharing content between two Activities in different projects:</h3> <p><strong>1.</strong> <code>SharedPreferences</code>, <code>SQLite</code>, <code>Serialization</code>, or <code>Content Providers</code>. These will all require you to break down your <em>Driver</em> Object into simple types. More on storage can be found in the <a href="http://developer.android.com/guide/topics/data/data-storage.html" rel="nofollow noreferrer">docs</a>.</p> <hr> <p><strong>2.</strong> <code>Parcelable</code>s can be shared via <code>Intent</code> between Activities.</p> <h3>There are several methods you can use for sharing content between two Activities in the same project:</h3> <p><strong>1.</strong> You can use <code>SharedPreferences</code>, <code>SQLite</code>, or <code>Serialization</code>. More on storage can be found in the <a href="http://developer.android.com/guide/topics/data/data-storage.html" rel="nofollow noreferrer">docs</a>.</p> <hr> <p><strong>2.</strong> You can set it to a static variable. For example, have a <code>Store</code> class where you save static variables:</p> <pre><code>public class Store { /** provides static reference to the driver */ public static Object driver; } </code></pre> <p>Then to set from anywhere, just do:</p> <pre><code>Store.driver = myDriver; </code></pre> <p>and to get from anywhere, just do:</p> <pre><code>Object driver = Store.driver; </code></pre> <hr> <p><strong>3.</strong> Create a custom <code>Application</code> 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 <a href="https://stackoverflow.com/questions/4572338/extending-application-to-share-variables-globally">Extending Application to share variables globally</a>.</p> <hr> <p><strong>4.</strong> The third option is to create a singleton accessor to your <code>Activity</code>. So, in your activity that has the driver referenced, add the following class variable:</p> <pre><code>private static MyActivity self;//replace MyActivity with the name of your class. </code></pre> <p>Then, add the getter:</p> <pre><code>public static MyActivity sharedMyActivity() { return self; } </code></pre> <p>Finally, add this line in <code>onCreate</code> (after the call to <code>super.onCreate(...)</code>):</p> <pre><code>self = this; </code></pre> <p>Now to access your driver (we'll say it has a getter), just call this from anywhere:</p> <pre><code>Object driver = MyActivity.sharedMyActivity().getDriver(); </code></pre> <hr> <p>As for <strong>part two of your question</strong> - if you are attempting to read from and write to a hardware device in an <code>Activity</code> that does not provide <code>USB</code> permissions, this will not work.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload