Is it possible to call an Activity
form inside the Activity
class, so I can deliver information over constructor?
something like
public MyClass(){
startActivity(new Intent(this, this.getClass()));
}
Is it possible to call an Activity
form inside the Activity
class, so I can deliver information over constructor?
something like
public MyClass(){
startActivity(new Intent(this, this.getClass()));
}
I'm assuming this is because you want to pass some initialisation data to the activity?
The way to do this is by adding a Bundle to the activity.
Intent intent = new Intent(YourStartingActivity.this,YourNewActivity.class);
intent.putExtra("key", "value");
startActivity(intent);
The in the OnCreate method of your new Activity
Bundle bundle = getIntent().getExtras();
String myString = bundle.getString("key");
Which will get whatever you passed in as your "value" which can be a String, int, float etc....
I think you can't do that. If I understood correctly you want to pass data between two activities, you should always do this via Intent. Take a look on this https://stackoverflow.com/a/2091482/3707606
If you want to pass more complex data you should make the data class implement Parcelable. It may look hard but you can generate your parcelable at http://www.parcelabler.com/ or install this plugin to Android Studio.