Example usage for android.app ActivityManager restartPackage

List of usage examples for android.app ActivityManager restartPackage

Introduction

In this page you can find the example usage for android.app ActivityManager restartPackage.

Prototype

@Deprecated
public void restartPackage(String packageName) 

Source Link

Usage

From source file:Main.java

@SuppressWarnings("deprecation")
public static void killProgram(Context context, String packageName) {
    ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    try {/* www. j  a  v a 2 s  .  c o m*/
        // 2.1 version
        mActivityManager.restartPackage(packageName);
    } catch (Exception e) {
        // 2.2 version
        mActivityManager.killBackgroundProcesses(packageName);
    }
}

From source file:Main.java

public static void killProcess(Context ctx, String pkgName) {
    ActivityManager actManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    // version 1.5 - 2.1
    if (android.os.Build.VERSION.SDK_INT <= 7) {
        actManager.restartPackage(pkgName);
    }/* ww w  . j av  a2s .  c  o m*/
    // version 2.2+
    else {
        actManager.killBackgroundProcesses(pkgName);
    }
}

From source file:Main.java

public static void releaseMemory(Context context) {
    ActivityManager activityManger = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> list = activityManger.getRunningAppProcesses();
    if (list != null) {
        for (int i = 0; i < list.size(); i++) {
            ActivityManager.RunningAppProcessInfo apinfo = list.get(i);
            String[] pkgList = apinfo.pkgList;
            if (apinfo.importance > ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE
                    && !apinfo.processName.equals("com.tt.realeasememory")) {
                for (int j = 0; j < pkgList.length; j++) {
                    if (Build.VERSION.SDK_INT >= 8) {
                        activityManger.killBackgroundProcesses(pkgList[j]);
                    } else {
                        activityManger.restartPackage(pkgList[j]);
                    }/*from   w  w w  . j a  v a  2 s. c o m*/
                }
            }
        }
    }
}

From source file:com.shivshankar.MyFirebaseMessagingService.java

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    Log.d("TAGRK", "From: " + remoteMessage.getFrom());
    String message = "", title = "", strImageURL = "";
    if (remoteMessage.getData() != null && remoteMessage.getData().size() > 0) {
        Log.d("TAGRK", "Message data payload: " + remoteMessage.getData());

        message = "" + remoteMessage.getData().get(Config.MESSAGE_KEY);
        title = "" + remoteMessage.getData().get(Config.TITLE_KEY);
        strImageURL = "" + remoteMessage.getData().get(Config.IMAGE_KEY);
    } else if (remoteMessage.getNotification() != null) {
        Log.d("TAGRK", "Message Notification Body: " + remoteMessage.getNotification().getBody());
        message = "" + remoteMessage.getNotification().getBody();
        title = "" + remoteMessage.getNotification().getTitle();
        strImageURL = "" + remoteMessage.getNotification().getIcon();
    }/*from ww  w .j  ava 2  s  . c o m*/

    if (strImageURL != null && !strImageURL.equals("") && !strImageURL.equals("null")) {
        Handler handler = new Handler(Looper.getMainLooper());
        final String finalTitle = title;
        final String finalMessage = message;
        final String finalStrImageURL = strImageURL;
        handler.post(new Runnable() {
            public void run() {
                new ServerAPICallImageBitmap(finalTitle, finalMessage, finalStrImageURL, "").execute();
            }
        });
    } else if (title.equalsIgnoreCase("Logout")) {
        try {
            SharedPreferences.Editor editor = AppPreferences.getPrefs().edit();
            editor.putString(commonVariables.KEY_LOGIN_ID, "0");
            editor.putBoolean(commonVariables.KEY_IS_LOG_IN, false);
            editor.putString(commonVariables.KEY_SELLER_PROFILE, "");
            editor.putString(commonVariables.KEY_BUYER_PROFILE, "");
            editor.putString(commonVariables.KEY_BRAND, "");
            editor.putBoolean(commonVariables.KEY_IS_BRAND, false);
            editor.putBoolean(commonVariables.KEY_IS_SELLER, false);
            editor.putBoolean(commonVariables.KEY_IS_SKIPPED_LOGIN_BUYER, false);
            editor.commit();
            android.os.Process.killProcess(android.os.Process.myPid());
            List<ApplicationInfo> packages;
            PackageManager pm;
            pm = getPackageManager();
            packages = pm.getInstalledApplications(0);

            ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
            String myPackage = getApplicationContext().getPackageName();
            for (ApplicationInfo packageInfo : packages) {
                if ((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1)
                    continue;
                if (packageInfo.packageName.equals(myPackage))
                    continue;
                mActivityManager.killBackgroundProcesses(packageInfo.packageName);
            }
            mActivityManager.restartPackage(myPackage);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else
        sendNotification(title, message);
    Log.i("TAGRK", "Received: " + remoteMessage.toString());
}

From source file:com.findcab.activity.LocationOverlay.java

/**
 * /*  w ww  .  j av  a2  s. c  o m*/
 * 
 * @param context
 */
public void exitPro(Context context) {

    // ?Application
    String packName = context.getPackageName();
    ActivityManager activityMgr = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    activityMgr.restartPackage(packName);
    activityMgr.killBackgroundProcesses(packName);
    android.os.Process.killProcess(android.os.Process.myPid());
}

From source file:org.uguess.android.sysinfo.ProcessManager.java

private void endProcess(ActivityManager am, String[] pkgs, String self) {
    if (pkgs != null) {
        for (String pkg : pkgs) {
            if (pkg != null) {
                int subKillType = Util.killable(pkg, self, ignoreList);

                if (subKillType == 0) {
                    am.restartPackage(pkg);
                }/*from  w  w  w .ja  v  a  2 s.c o m*/
            }
        }
    }
}