Xamarin.android Android:开始一个新的意图

Xamarin.android Android:开始一个新的意图,xamarin.android,Xamarin.android,我的目标是安卓4.4,并开始了这样的服务 start.Click += delegate { StartService(new Intent("com.xamarin.LocationService")); start.Enabled = false; stop.Enabled = true; }; 一切都很好。现在我的目标是6.0,从中我发现这是不安全的,我应该这样做: Intent serviceIntent = new Intent(conte

我的目标是安卓4.4,并开始了这样的服务

start.Click += delegate {
    StartService(new Intent("com.xamarin.LocationService"));
    start.Enabled = false;
    stop.Enabled = true;
};
一切都很好。现在我的目标是6.0,从中我发现这是不安全的,我应该这样做:

Intent serviceIntent = new Intent(context,MyService.class);
context.startService(serviceIntent);
但我无法确定“newintent()”的参数应该是什么。类名为“LocationActivity”,但如果我这样做

serviceIntent = new Intent(this, typeof(LocationActivity));
context.startService(serviceIntent);
它编译正常,但服务实际上没有启动

这条线索中有标记的答案也表明了这一点

Intent bi = new Intent("com.android.vending.billing.InAppBillingService.BIND");
bi.setPackage("com.android.vending");
但如果我尝试这样做,我会发现“Intent不包含setPackage的定义”


有人能帮我解决这个问题吗?提前感谢。

如果你想开始一项活动,你需要使用StartActivity而不是StartService 然后使用这个,但从StartService更改为StartActivity

啊!!我确实想启动一项服务,而不是一项活动。因此,我的参数应该是我要启动的服务的类型,而不是启动它的活动的类型!。因此,您的回答间接地引导我找到了解决方案:
newintent(这个,typeof(LocationService))
serviceIntent = new Intent(this, typeof(LocationActivity));
context.startService(serviceIntent);
serviceIntent = new Intent(this, typeof(LocationActivity));
context.StartActivity(serviceIntent);