2011-10-04 46 views
-1

我正在製作一個應用程序,我要設置我的主要活動,即在電話啓動時,我的應用程序應檢查是否存在SD卡中的特定文件,然後它應該移至其他活動。 任何幫助將不勝感激。 謝謝在啓動時選擇活動

回答

1

我thnk,你應該使用標誌的概念:

if (data.contains("1")) 
     { 
      Intent intent1 = new Intent(context, NewClasss.class); 
      intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      context.startActivity(intent1); 
     } 
     else if (data.contains("2")) 
     { 

         //list of classes 
         // basically you have to set flag 
      } 
+0

什麼提到在其他部分作爲我的應用程序是後臺應用程序? – Aditya1510

+1

In if(data.contains 1)您必須編寫主要活動,並且在2中您必須提及除主要活動外的所有活動 – 2011-12-12 07:00:10

+0

感謝您的幫助 – Aditya1510

6

使用BroadcastReceiver與引導意圖。

在清單中,添加:

<receiver android:name=".Receiver"> 
    <intent-filter> 
     <action android:name="android.intent.action.BOOT_COMPLETED" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter> 
    </receiver> 

還添加權限:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 

然後實現類擴展廣播接收器,這將在處理的onReceive Intent.ACTION_BOOT_COMPLETED行動,做你的任務有(啓動服務等)。

+0

你也可以創建一個活動,而不是一個接收器,我相信更多的是這樣一個問題行。 – spatulamania

+0

是的,可能。但問題是也檢查一些文件的存在,這不需要活動。 –

+0

我認爲最好的方法是創建一個接收器,檢查該文件,並基於該文件決定啓動該活動並創建適當的意圖。 –