小编Dmi*_*7ry的帖子

地理位置,服务和本地通知

我正在尝试制作我的第一个与地理位置和本地通知相关的Android系统应用程序.我想像这样......有基本的活动MainActivity.启动后,它会启动一项服务TestService,在更改坐标的情况下,将它们发送到服务器上,并作为回复接收一些将显示为本地通知的消息.我有一些问题.

  1. 如果我关闭应用程序(使用任务管理器),那么服务将停止,因此在更改坐标后没有任何反应.我需要做什么一直服务工作?或者这不可能?

  2. 激活本地通知后,它会启动NotifyActivity,显示详细信息.我点击buttonDelete它 - 它将关闭NotifyActivity并开始MainActivity.但是如果之后我切换到操作系统屏幕(使用Back按钮)并返回(使用任务管理器),那么"MainActivity"将再次显示为"NotifyActivity".为什么会发生以及如何避免它?

主要活动

[Activity(Label = "LocationTest", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.Main);

        var button = FindViewById<Button>(Resource.Id.myButton);
        button.Click += delegate {
            StartService(new Intent(this, typeof(TestService)));
            button.Text = "Started";
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

地理位置服务

[Service]
public class TestService : Service, ILocationListener
{
    // Start service
    public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int …
Run Code Online (Sandbox Code Playgroud)

c# android xamarin

8
推荐指数
1
解决办法
404
查看次数

标签 统计

android ×1

c# ×1

xamarin ×1