I`m trying to parse an object from my my main activity to a new activity that starts when the user clicks a button. I’ve seached the internet and found how to parse primative types and custom made classes that implements parceble or serilizable, but can’t find any information on how to transfeer a raw object.
I’ll write psuedo-code of what I`m trying to achive below:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
loadConnectInfo();
View connectButton = findViewById(R.id.connectButton);
connectButton.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.connectButton:
Intent i = new Intent(this, NewClass.class);
Socket s = connect(); // this is the object I want to parse to to "NewClass"
startActivity( i);
break;
}
You can’t pass an object that is neither serializable nor parcelable between activities this way. What you probably want to do in this case is make your code that manages and interacts with the socket into a service and bind to that service in all the activities that need to use it.