Code example for Intent

Methods: startActivityaddCategorysetFlags, sleep

0
        Log.i(TAG, "Starting " + appName);
 
        if (!mNameToProcess.containsKey(appName))
            throw new NameNotFoundException("Could not find: " + appName);
 
        String process = mNameToProcess.get(appName);
        Intent startIntent = mNameToIntent.get(appName);
 
        AppLaunchRunnable runnable = new AppLaunchRunnable(startIntent);
        Thread t = new Thread(runnable);
        t.start();
        try { 
            t.join(JOIN_TIMEOUT);
        } catch (InterruptedException e) {
            // ignore 
        } 
 
        return process;
    } 
 
    private void closeApp() { 
        Intent homeIntent = new Intent(Intent.ACTION_MAIN);
        homeIntent.addCategory(Intent.CATEGORY_HOME);
        homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        getInstrumentation().getContext().startActivity(homeIntent);
        sleep(3000); 
    } 
 
    private void measureMemory(String appName, String processName,
            Bundle results) {
        List<Integer> pssData = new ArrayList<Integer>();
        int pss = 0;
        int iteration = 0;
        while (iteration < MAX_ITERATIONS) {
            sleep(SLEEP_TIME);
            pss = getPss(processName);
            Log.i(TAG, appName + "=" + pss);
            if (pss < 0) {
                reportError(appName, processName, results);
                return; 
            } 
            pssData.add(pss);
            if (iteration >= MIN_ITERATIONS && stabilized(pssData)) {
                results.putInt(mNameToResultKey.get(appName), pss);
                return; 
            } 
            iteration++;
        } 
 
        Log.w(TAG, appName + " memory usage did not stabilize");
        results.putInt(mNameToResultKey.get(appName), average(pssData));
    } 
 
    private int average(List<Integer> pssData) {
        int sum = 0;
        for (int sample : pssData) {
            sum += sample;
        } 
 
        return sum / pssData.size();
    } 
 
    private boolean stabilized(List<Integer> pssData) {
        if (pssData.size() < 3)
            return false;