Spi*_*ner 16 service android android-service
我正在尝试创建一个将在后台处理文件I/O的服务.更新数据的活动将绑定到服务并调用服务的方法来执行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();
Run Code Online (Sandbox Code Playgroud)
在第3行,LogCat输出一个ComponentInfo对象,因此看起来服务已经创建; 但是,短信是空的.此外,似乎永远不会调用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;
}
Run Code Online (Sandbox Code Playgroud)
我从未在LogCat中看到任何"启动服务"输出,也没有看到Toast.
我的服务在我的清单中声明为:
<service android:name=".SurveyManagerService" android:exported="false" android:enabled="true">
</service>
Run Code Online (Sandbox Code Playgroud)
我错过了一些明显的东西吗 让我知道我应该提供哪些其他信息来诊断问题.
Def*_*era 16
请务必在AndroidManifest.xml中声明您的服务
<application>
...
<service android:name=".path.to.service.MyService"/>
</application>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
19183 次 |
最近记录: |