2012-05-30 65 views
0

我正在製作一個應用程序,我在手機上獲取安裝應用程序的列表,然後點擊並從我的應用程序中打開這些應用程序。但這裏的問題籌集CATEGORY_LAUNCHER它給空指針從另一個打開的應用程序問題

我logcat的輸出::

05-30 14:34:33.876: E/Handler(14042): Failed to handle callback; interface not implemented, callback:[email protected] 
05-30 14:34:33.876: E/Handler(14042): java.lang.NullPointerException 
05-30 14:34:33.876: E/Handler(14042): at com.AppFavorits.GetAllApp$1$1.onClick(GetAllApp.java:83) 
05-30 14:34:33.876: E/Handler(14042): at android.view.View.performClick(View.java:3538) 
05-30 14:34:33.876: E/Handler(14042): at android.widget.CompoundButton.performClick(CompoundButton.java:105) 
05-30 14:34:33.876: E/Handler(14042): at android.view.View$PerformClick.run(View.java:14330) 
05-30 14:34:33.876: E/Handler(14042): at android.os.Handler.handleCallback(Handler.java:607) 
05-30 14:34:33.876: E/Handler(14042): at android.os.Handler.dispatchMessage(Handler.java:92) 
05-30 14:34:33.876: E/Handler(14042): at android.os.Looper.loop(Looper.java:154) 
05-30 14:34:33.876: E/Handler(14042): at android.app.ActivityThread.main(ActivityThread.java:4974) 
05-30 14:34:33.876: E/Handler(14042): at java.lang.reflect.Method.invokeNative(Native Method) 
05-30 14:34:33.876: E/Handler(14042): at java.lang.reflect.Method.invoke(Method.java:511) 
05-30 14:34:33.876: E/Handler(14042): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
05-30 14:34:33.876: E/Handler(14042): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
05-30 14:34:33.876: E/Handler(14042): at dalvik.system.NativeStart.main(Native Method) 

我這個:: 更新代碼

final Dialog dialog = new Dialog(GetAllApp.this); 
        dialog.setContentView(R.layout.maindialog); 
        dialog.setTitle("This is my custom dialog box"); 
        dialog.setCancelable(true); 
        //there are a lot of settings, for dialog, check them all out! 

        //set up text 
        final RadioButton rdoDialogopen = (RadioButton)dialog.findViewById(R.id.rdoDialogopen); 
        final RadioButton rdoDialogfav = (RadioButton)dialog.findViewById(R.id.rdoDialogfav); 
        final RadioButton rdoDialogopenNfav = (RadioButton)dialog.findViewById(R.id.rdoDialogopenNfav); 

       rdoDialogopen.setOnClickListener(new View.OnClickListener() { 
        public void onClick(View v) { 
         if (rdoDialogopen.isChecked() == true) { 
          if(lstpinfo.get(position).pname !=null) 
          { 
          Intent i = new Intent(Intent.ACTION_MAIN); 
          PackageManager manager = getPackageManager(); 
          i = manager.getLaunchIntentForPackage(lstpinfo 
            .get(position).pname); 
          i.addCategory(Intent.CATEGORY_LAUNCHER); 
          startActivity(i); 

          } 

         } 

        } 

       }); 
+0

發佈您的代碼,你有一個空指針異常中的onClick –

+0

請參閱GetAllApp.java的第83行 –

+0

@K_Anas我已更新它 –

回答

0

如果你是從後臺啓動應用程序,則必須設置FLAG_ACTIVITY_NEW_TASKFLAG_FROM_BACKGROUND在你的意圖對象唱addFlags爲:

Intent intent25 = new Intent(Intent.ACTION_MAIN).addCategory(
Intent.CATEGORY_LAUNCHER).setClassName("_APP_PACKAGE_NAME", 
"_APP_PACKAGE_NAME.ACTIVITY_NAME").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) 
.addFlags(Intent.FLAG_FROM_BACKGROUND).setComponent(new ComponentName("APP_PACKAGE_NAME", 
"APP_PACKAGE_NAME.ACTIVITY_NAME")); 
getApplicationContext().startActivity(intent25); 

我考慮你知道我們是如何解壓包名稱和PackageManager

0

我想不出你有什麼問題活動名稱,你要貼得更碼!!

,但你必須看到this教程,因爲它具有相同的問題涉及和你

  1. 列出所有的手機上安裝的應用程序上的一個ListView
  2. 通過調用它的推出意圖
  3. 開始點擊的應用

下載的代碼它連接太

相關問題