Intent intent = new Intent(this, typeof(DownloaderService));
intent.PutExtra("id", ID);
StartService(intent);
下面是作为前台服务启动服务的方式,这是DownloaderService类中的
代码语言:
javascript
复制
public override void OnCreate()
//Start this service as foreground
Intent notificationIntent = new Intent(this, typeof(VideoDownloaderService));
PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0,
notificationIntent, 0);
Notification notification = new Notification.Builder(this)
.SetSmallIcon(Resource.Drawable.Icon)
.SetContentTitle("Initializing")
.SetContentText("Starting The Download...")
.SetContentIntent(pendingIntent).Build();
StartForeground(notificationID, notification);
}
以下是我如何处理意图
代码语言:
javascript
复制
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
var id = intent.GetStringExtra("id");
Task.Factory.StartNew(async () => {
await download(id);
StopForeground(false);