我的目标是android 4.4并且正在启动这样的服务
start.Click += delegate {
StartService(new Intent("com.xamarin.LocationService"));
start.Enabled = false;
stop.Enabled = true;
};
Run Code Online (Sandbox Code Playgroud)
这一切都很好.现在我的目标是6.0,并从这个线程中发现这不安全,我应该这样做:
Intent serviceIntent = new Intent(context,MyService.class);
context.startService(serviceIntent);
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚'新Intent()'的论据应该是什么.类名是'LocationActivity'但是如果我这样做的话
serviceIntent = new Intent(this, typeof(LocationActivity));
context.startService(serviceIntent);
Run Code Online (Sandbox Code Playgroud)
它编译好,但服务实际上没有启动.
该线程中的明确答案也表明了这一点
Intent bi = new Intent("com.android.vending.billing.InAppBillingService.BIND");
bi.setPackage("com.android.vending");
Run Code Online (Sandbox Code Playgroud)
但如果我尝试,我发现'Intent不包含setPackage的定义'.
那么,有人可以帮我解决这个问题吗?提前致谢.
小智 8
如果要启动活动,则需要使用StartActivity而不是StartService然后使用此命令,但从StartService更改为StartActivity.
从
serviceIntent = new Intent(this, typeof(LocationActivity));
context.startService(serviceIntent);
Run Code Online (Sandbox Code Playgroud)
至
serviceIntent = new Intent(this, typeof(LocationActivity));
context.StartActivity(serviceIntent);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3619 次 |
| 最近记录: |