In Java, the java.io.serializable implement the serialisation. You can write a Java class to implement the Serializable interface.
class IsSerializable implements Serializable
{
private String plug = "Plugin to Java!";
public IsSerializable()
{
try
{
FileOutputStream out = new FileOutputStream("/mnt/sdcard/yes-out.txt");
ObjectOutputStream oos = new ObjectOutputStream(out);
oos.writeObject(this);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
IsSerializable is = new IsSerializable();
...
}
If you run this code, there is an error message:
The reason is that you can't get the whole class to be serialised.
Solution:
If we replace oos.writeObject(this); with oos.writeObject(plug); the problem is fixed.
Techlancers Middle East is a leading digital transformation company in Dubai, helping businesses embrace innovation through advanced software solutions and strategic technology adoption. Our expert app developers in Dubai craft high-performance mobile applications tailored to unique business needs. With deep expertise in software development, we deliver scalable, secure, and future-ready digital products.
ReplyDelete