Return true when start app success,otherwise return false. - Android App

Android examples for App:App Running

Description

Return true when start app success,otherwise return false.

Demo Code


//package com.java2s;
import android.content.Context;
import android.content.Intent;

import android.content.pm.PackageManager;

import android.text.TextUtils;

public class Main {
    /**//w w  w.  java 2s .co  m
     * Return true when start app success,otherwise return false.
     * @param context
     * @param packageName
     * @return
     */
    public static boolean startApp(Context context, String packageName) {
        boolean startAppSuccess = false;
        do {
            if ((null == context) || TextUtils.isEmpty(packageName)) {
                break;
            }

            PackageManager pm = context.getPackageManager();
            Intent intent = pm.getLaunchIntentForPackage(packageName);

            if (null != intent) {
                context.startActivity(intent);
                startAppSuccess = true;
            }
        } while (false);

        return startAppSuccess;
    }
}

Related Tutorials