我正在尝试创建一个能够在后台处理文件输入/输出的服务。更新数据的活动将绑定到该服务并调用其方法来执行I/O操作。在此过程中,我参考了Android文档。
然而,我的服务似乎无法启动。在我的Activity的onCreate()方法中,我有以下代码:
Intent smsIntent = new Intent(this, SurveyManagerService.class);
String surveyFilename = getIntent().getStringExtra("surveyFilename");
System.out.println(startService(smsIntent)); //testing if it starts
SurveyManagerServiceConnection connection = new SurveyManagerServiceConnection();
sms = connection.getSurveyManagerService();
在第三行,LogCat输出一个ComponentInfo对象,因此似乎服务已经创建;然而sms为空。此外,SurveyManagerService的onStartCommand()方法似乎从未被调用:
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
System.out.println("starting service");
Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show();
openSurveyFromIntent(intent);
return START_REDELIVER_INTENT;
}
我从LogCat中从未看到任何“启动服务”的输出,也不会出现Toast提示。
我的服务在清单文件中声明为:
<service android:name=".SurveyManagerService" android:exported="false" android:enabled="true">
</service>
我是否遗漏了一些显而易见的东西?请让我知道我需要提供哪些其他信息来诊断问题。