Reputation: 151
I wonder if this is possible, the truth I imagine it must be a bad practical but only to test some things. I would like to call the same activity from itself, not if I explain.
Call to Activity A from Activity A
what I get is clean all sight. I've tried calling the method onResume
, onRestart
but I can not get it to work, for some strange reason the application stops working.
Nor I can see the error, since USB have connected the Code bar reader and not the device connected to the computer to view the log.
Upvotes: 0
Views: 7221
Reputation: 1632
This is the best way to refresh your activity:
public void refresh() {
Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
overridePendingTransition(0, 0);
startActivity(intent);
}
EDIT 06.11.2021 Kotlin way to refresh activity
private fun refresh() {
val intent = Intent(applicationContext, YourActivity::class.java)
startActivity(intent)
finish()
}
Upvotes: 5
Reputation: 335
Intent intent = getIntent();
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
finish();
startActivity(intent);
Upvotes: 0
Reputation: 3
Intent intent = new Intent(getApplicationContext(),YourActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Upvotes: 0
Reputation: 843
Use intents.
Intent intent = new Intent(this, A.class);
startactivity(intent);
finish(); // assuming you wish to kill your previous instance of the activity
Upvotes: 3