2011-10-04 50 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

我认为最好的方法是创建一个接收器,检查该文件,并基于该文件决定启动该活动并创建适当的意图。 –