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


2 answers


Do you want to provide an option to log out of your own application? If so, why should you use broadcast receivers? Why not try

android.os.Process.killProcess (android.os.Process.myPid ());



onBackPressed () method?

+2


source


Refer Link: to disable home key, menu key and back key



How to block home key

+1


source







All Articles