Redirect to app in less than 3 seconds
I am trying to develop an android application so that the user cannot log out of the application with just the logout button.
I am using Broad Cast receiver, onReceive
check if the currently running app is my app; if yes -> continue, Else -> redirect to my application.
my question now is the interval in the receiver (3 seconds), but the app takes 5-6 seconds to reopen the app. How to redirect an application in less than 3 seconds?
code:
Manifest declaration:
<receiver android:name=".AlarmReciever" />
Receiver implementation:
public class AlarmReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
ActivityManager am1 = (ActivityManager)context.getSystemService(Activity.ACTIVITY_SERVICE);
String packageName = am1.getRunningTasks(1).get(0).topActivity.getPackageName();
if (packageName.equals("com.XXXX.YYYYY")) {
//continue;
}else{
final Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName("com.XXXX.YYYYY", "com.XXXX.YYYYY.Launch");
thisActivity.startActivity(intent);
thisActivity.finish();
}
}
}
+3
source to share