read


“implement your class with Serializable. Let’s suppose that this is your entity class:

<pre class="default prettyprint" style="background-color: #eeeeee; border-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto;">import java.io.Serializable;
@SuppressWarnings("serial") //with this annotation we are going to hide compiler warning
public class Deneme implements Serializable {
public Deneme(double id, String name){
   
this.id = id;
   
this.name = name;
}
public double getId() {
   
return id;
}
public void setId(double id) {
   
this.id = id;
}
public String getName() {
   
return this.name;
}
public void setName(String name) {
   
this.name = name;
}
private double id;
private String name;
}
</pre><div style="background-color: white; border-width: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">we are sending the object called dene from X activity to Y activity. Somewhere in X activity;</div><pre class="default prettyprint" style="background-color: #eeeeee; border-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto;">Deneme dene = new Deneme(4,"Mustafa");
Intent i = new Intent(this, Y.class);
i
.putExtra("extraID", dene);
startActivity
(i);
</pre><div style="background-color: white; border-width: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">In Y activity we are getting the object.</div><pre class="default prettyprint" style="background-color: #eeeeee; border-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto;">Intent i = getIntent();
Deneme dene = (Deneme)i.getSerializableExtra("extraID
);</pre><div style="background-color: white; border-width: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">that’s it.”</div><div style="background-color: white; border-width: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">Source</div>

Blog Logo

Daniel Gomez Rico


Published

Image

MakinGIANTS

The findings and tips records of an Android-iOS-TheWholeShabang group

Back to Overview