Reputation: 337
I'm using the android Bluetooth library to connect to a remote desktop. When the connection with the desktop is lost, I'd like to restart a fresh instance of the application (that would highly facilitate the handling of my connection lost).
I tried this code :
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage( getBaseContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
But after that, I still have trouble reconnecting whereas if I manually kill and restart the application it works fine.
Upvotes: 0
Views: 403
Reputation: 1274
Are you sure you want to be restarting the Activity? The user will see the transitions and it will be a more sluggish application. Also, restarting an Activity is very different from restarting the application.
There is probably an issue with how you connect to the remote and it may be beneficial to debug that. If you post your code maybe others can help.
Upvotes: 0
Reputation: 5562
You can restart your Activity
when you detect that you've lost and found again the connection. You can restart your activity with this code:
public void reload() {
Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
overridePendingTransition(0, 0);
startActivity(intent);
}
Upvotes: 1