如果我有以下代码:
Intent intent = new Intent(this,DownloadService.class);
for(int i=0;i<filesArray.length;i++){
startService(intent);
}
Run Code Online (Sandbox Code Playgroud)
在此代码中DownloadService扩展IntentService.
所以现在,当我打电话时startService(intent),这意味着每次调用我都会启动一项新服务,startService(intent)或者这意味着它DownloadService会运行一次,然后每次调用startService(intent)它时,只会使用不同的startId传递不同的意图.
这是否有意义,以及其中哪一个是这样的?
如何获取Service从调用传递的Android 中的数据Activity?
我想定期向服务器发送数据,我正在使用后台Service,但我希望在数据更新时发送,并且我正在进入的更新数据Activity和Service后台运行..所以我怎么能通过数据运行Service的Activity.使用Intent我只能在启动时发送一次数据Service.
Intent serviceIntent= new Intent(DriverActivity.this,demoService.class);
serviceIntent.putExtra("token", token);
startService(serviceIntent);
Run Code Online (Sandbox Code Playgroud)