Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 难以启动(同时)通过应用程序安装的应用程序_Android - Fatal编程技术网

Android 难以启动(同时)通过应用程序安装的应用程序

Android 难以启动(同时)通过应用程序安装的应用程序,android,Android,我是android新手。实际上,我正试图通过我的应用程序增加android手机的RAM内存。为此,我创建了一个活动,可以启动手机中的其他应用程序。这种方法成功地减少了RAM内存。但我面临一个困难,因为在应用程序启动后,我看不到父活动。我需要在其他活动(已启动)启动后立即将其推送到后台运行,并且始终需要父活动可见 package com.android; import java.util.List; import android.app.Activity; import android.app.

我是android新手。实际上,我正试图通过我的应用程序增加android手机的RAM内存。为此,我创建了一个活动,可以启动手机中的其他应用程序。这种方法成功地减少了RAM内存。但我面临一个困难,因为在应用程序启动后,我看不到父活动。我需要在其他活动(已启动)启动后立即将其推送到后台运行,并且始终需要父活动可见

package com.android;

import java.util.List;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.MemoryInfo;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.Handler;
import android.widget.LinearLayout;
import android.widget.Toast;
/**
 * GraphViewDemo creates some dummy data to demonstrate the GraphView component.
 * @author Arno den Hond
 **/
public class VsActivity extends Activity {
  /**
     * Variable Array for GraphView
     * verlabel : Background Height Values
     * horlabel : Background Width Values
     * values : Max Values of Foreground Active Graph
     */
    private float[] values = new float[60]; 
    long availableMegs;
    private String[] verlabels = new String[]     { "500","450","400","350","300","250","200","150","100","50","0"};
    private String[] horlabels = new String[] {"0","10", "20", "30", "40", "50", "60"};
    private GraphView graphView;
    private LinearLayout graph;
    private boolean runnable = false;
    public static int datasend,test=0;
    int cnt=0;
    Activity activity = this.activity;
    static int count=0;
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        graph = (LinearLayout)findViewById(R.id.graph);
        graphView = new GraphView(this, values, "TEST GRAPH", horlabels, verlabels,    GraphView.LINE);
        graph.addView(graphView);
        runnable = true;
        startDraw.start();
    }

    @Override
    public void onDestroy(){
        super.onDestroy();
        runnable = false;
    }

    public void setGraph(){
        int i,j;
        count=count+10;
        try{
                j=values.length-1;
        for(i=0; i<values.length-1; i++){
            values[i] = values[i+1];
        }
        MemoryInfo mi = new ActivityManager.MemoryInfo();
        ActivityManager activityManager = (ActivityManager) getApplicationContext()
            .getSystemService(ACTIVITY_SERVICE);
        activityManager.getMemoryInfo(mi);
        datasend= (int)((mi.availMem / 1048576));
 values[values.length-1] = (float) datasend;        
graph.removeView(graphView);
        graph.addView(graphView);
        }
        catch (Exception e){
            // e.printstacktrace();
        }
    } 

private void  launchComponent(String packageName, String name){
    System.out.println("launch application "+datasend);
    Intent launch_intent = new Intent("android.intent.action.MAIN");
    launch_intent.addCategory("android.intent.category.LAUNCHER");
    launch_intent.setComponent(new ComponentName(packageName, name));
    launch_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if(datasend > 24){
        System.out.println("launch application inside if "+packageName+"   "+name);
    this.startActivity(launch_intent);
    }
}

public void startApplication(){
    String application_name = "";
    test=1;
    //ContextWrapper activity = this.activity;
    try{
        System.out.println("Start application ");
        Intent intent = new Intent("android.intent.action.MAIN");
        intent.addCategory("android.intent.category.LAUNCHER");
        List<android.content.pm.PackageInfo> packageList;
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        PackageManager pm = this.getPackageManager();
        packageList = pm.getInstalledPackages(0);
        List<ResolveInfo> resolveinfo_list = pm.queryIntentActivities(intent, 0);

        for(ResolveInfo info:resolveinfo_list){
            application_name = info.activityInfo.packageName;
            System.out.println(info.activityInfo.packageName+"    "+info.activityInfo.name);
            //if(info.activityInfo.packageName.equalsIgnoreCase(application_name)){
                launchComponent(info.activityInfo.packageName, info.activityInfo.name);
              //  break;
           // }
        }
    }
    catch (ActivityNotFoundException e) {
        Toast.makeText(activity.getApplicationContext(), "There was a problem loading the application: "+application_name,Toast.LENGTH_SHORT).show();
    }
}
public Handler handler = new Handler(){
    @Override
    public void handleMessage(android.os.Message msg){
        switch(msg.what){

        case 0x01:
           setGraph();
          // if(test == 0){
          startApplication();//}
           break;
        }
    }
};

public Thread startDraw = new Thread(){
    @Override
    public void run(){
        while(runnable){
            handler.sendEmptyMessage(0x01);
            try{
                MemoryInfo mi = new ActivityManager.MemoryInfo();
                ActivityManager activityManager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
                activityManager.getMemoryInfo(mi);
                long ava = mi.availMem / 1048576L;
                //count=(int)ava;
                //System.out.println("SUDARHAN RAMAN    "+ava+"   "+count);
                Thread.sleep(1000);
            } catch (Exception e){
                // e.printstacktrace();
            }
        }
    }
};
}
package.com.android;
导入java.util.List;
导入android.app.Activity;
导入android.app.ActivityManager;
导入android.app.ActivityManager.MemoryInfo;
导入android.content.ActivityNotFoundException;
导入android.content.ComponentName;
导入android.content.Context;
导入android.content.ContextWrapper;
导入android.content.Intent;
导入android.content.pm.PackageManager;
导入android.content.pm.ResolveInfo;
导入android.os.Bundle;
导入android.os.Handler;
导入android.widget.LinearLayout;
导入android.widget.Toast;
/**
*GraphViewDemo创建一些虚拟数据来演示GraphView组件。
*@作者Arno den Hond
**/
公共类VsActivity扩展了活动{
/**
*GraphView的变量数组
*verlabel:背景高度值
*horlabel:背景宽度值
*值:前景活动图的最大值
*/
私有浮点[]值=新浮点[60];
长期可用性;
私有字符串[]verlabels=新字符串[]{“500”、“450”、“400”、“350”、“300”、“250”、“200”、“150”、“100”、“50”、“0”};
私有字符串[]horlabels=新字符串[]{“0”、“10”、“20”、“30”、“40”、“50”、“60”};
私人GraphView GraphView;
私有线性布局图;
私有布尔值runnable=false;
公共静态int datasend,test=0;
int-cnt=0;
Activity=this.Activity;
静态整数计数=0;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
图=(线性布局)findViewById(R.id.graph);
graphView=新的graphView(此,值,“测试图”、horlabels、verlabels、graphView.LINE);
graph.addView(graphView);
runnable=true;
startDraw.start();
}
@凌驾
公共空间{
super.ondestory();
runnable=false;
}
公共无效集合图(){
int i,j;
计数=计数+10;
试一试{
j=值。长度-1;
对于(i=0;i 24){
System.out.println(“如果”+packageName+“”+name,则在内部启动应用程序”);
这就是startActivity(发射意图);
}
}
公共无效startApplication(){
字符串应用程序_name=“”;
测试=1;
//ContextWrapper活动=this.activity;
试一试{
System.out.println(“启动应用程序”);
Intent-Intent=newintent(“android.Intent.action.MAIN”);
addCategory(“android.intent.category.LAUNCHER”);
包装商名单;
intent.addFlags(intent.FLAG\u活动\u无\u动画);
PackageManager pm=this.getPackageManager();
packageList=pm.getInstalledPackages(0);
List resolveinfo_List=pm.querytentActivities(intent,0);
对于(ResolveInfo:ResolveInfo_列表){
应用程序名称=info.activityInfo.packageName;
System.out.println(info.activityInfo.packageName+“”+info.activityInfo.name);
//if(info.activityInfo.packageName.equalsIgnoreCase(应用程序名称)){
启动组件(info.activityInfo.packageName、info.activityInfo.name);
//中断;
// }
}
}
捕获(ActivityNotFounde异常){
Toast.makeText(activity.getApplicationContext(),“加载应用程序时出现问题:“+application\u name,Toast.LENGTH\u SHORT).show();
}
}
公共处理程序=新处理程序(){
@凌驾
public void handleMessage(android.os.Message msg){
开关(msg.what){
案例0x01:
setGraph();
//如果(测试==0){
startApplication();//}
打破
}
}
};
公共线程startDraw=新线程(){
@凌驾
公开募捐{
while(可运行){
handler.sendEmptyMessage(0x01);
试一试{
MemoryInfo mi=新建ActivityManager.MemoryInfo();
ActivityManager ActivityManager=(ActivityManager)getSystemService(ACTIVITY_服务);
activityManager.getMemoryInfo(mi);
长ava=mi.availem/1048576L;
//计数=(int)ava;
//System.out.println(“SUDARHAN RAMAN”+ava+”+count);
睡眠(1000);
}捕获(例外e){
//e.printstacktrace();
}
}
}
};
}
这里的GraphView是一个使用Canvas.drawline(…)绘制图形的视图 在上述代码中,startapplication()将启动子应用程序(安装在手机中的应用程序)活动


Plz help…

这将启动我们手机中的所有应用程序?如何知道应用程序是否已启动?…如果我的问题很傻,请原谅我,因为我是android新手..你想做什么?你想从自己的活动或任何其他方式打开手机中安装的应用程序吗?我有这样一个场景要做..b基本上,我需要做压力测试,比如,我们有两个场景/环境1)基于降低电池电量和测试,2)增加Ram内存和内部内存使用率和测试…现在我们需要2设置一个环境,比如上面的几点和den做压力测试一个应用程序…为了提高Ram使用率,我想启动multiple是的,先生,我需要打开从我自己的活动安装的应用程序,而不是您可以打开它
     Intent i = new Intent(Intent.ACTION_MAIN);
            PackageManager manager = mContext.getPackageManager();
            i = manager.getLaunchIntentForPackage(_AppPkgName);
            i.addCategory(Intent.CATEGORY_LAUNCHER);
            startActivity(i);