2012-06-26 160 views
0

我是新来的机器人..实际上我试图增加内存的Android手机通过我的应用程序..为此,我创建了一个活动,我可以启动其他应用程序出现在我们的手机中。这种方法正在成功减少RAM内存。但我面临着一个困难,因为我无法在应用程序启动后看到PARENT活动。我需要按其他活动(被推出),以在后台,只要它已经推出,总是我需要的家长活动是可见的运行..难以通过应用程序启动应用程序(同时)

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(); 
      } 
     } 
    } 
}; 
} 

这里GraphView是查看这将吸引使用Canvas.drawline(...) 在上面的代码startapplication()将启动子活动(安装在我们的手机应用程序)的图..

plz帮助...

回答

0
 Intent i = new Intent(Intent.ACTION_MAIN); 
      PackageManager manager = mContext.getPackageManager(); 
      i = manager.getLaunchIntentForPackage(_AppPkgName); 
      i.addCategory(Intent.CATEGORY_LAUNCHER); 
      startActivity(i); 
+0

这将lau所有在我们手机上的应用程序?如何知道该应用是否启动? ...如果我的问题是愚蠢的原谅我bcoz iam新的Android .. – Sudarshan

+0

你想要做什么。你想从自己的活动或其他任何活动中打开安装在手机中的应用程序吗? – skygeek

+0

我得到了这样的情景做..基本上我需要做压力测试像东西,因为我们有2场景/环境1)基于降低电池电量和测试,2)增加RAM内存和内存使用和测试...现在我们需要2建立一个像上面的点和书房环境做压力测试应用程序...为了增加Ram的使用我想从一个应用程序启动多个应用程序.. – Sudarshan

相关问题