【问题标题】:monodroid for android serviceandroid 服务的 monodroid
【发布时间】:2011-11-24 22:31:07
【问题描述】:

我想使用 monodroid 开发一个作为后台服务运行的 android 应用程序。

任何人都可以提供有关如何执行此操作的示例代码的指针吗?

谢谢!

【问题讨论】:

    标签: android mono xamarin.android


    【解决方案1】:

    我的samples on GitHub 中有一个基本服务示例。基本思想是,您定义一个扩展 Service 的类并使用 Service 属性对其进行装饰,以便在 AndroidManifest.xml 中生成适当的配置(您可以选择自己执行此操作,但您应该很少需要这样做)。

    [Service]
    public class MusicService : Service
    {
        public override IBinder OnBind(Intent intent)
        {
            return null;
        }
    
        public override void OnCreate()
        {
            base.OnCreate();
    
            // ...
        }
    
        public override void OnStart(Intent intent, int startId)
        {
            base.OnStart(intent, startId);
    
            // ...
        }
    
        public override void OnDestroy()
        {
            base.OnDestroy();
    
            // ...
        }
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多