对于Android服务Onresume方法 [英] Onresume method for Android services

查看:213
本文介绍了对于Android服务Onresume方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让这等待NFC标签和做一些事情的服务。我可以用下面的一个活动code座做,但也没办法,即使研究后,如何实现它的服务。

I am trying to make a service which waits NFC tags and does something. I can do it with following code block in an activity but have no idea, even after researches, how to implement it in a service.

@Override
protected void onResume() {
    super.onResume(); // Sticky notes received from Android if
    enableNdefExchangeMode();

    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
        do_something();
    }
}

我想这样做的一个服务。我不能使用super.onResume()。我应该怎么用这个来替代,或者该怎么办呢?

I want to do this in a service. i can not use super.onResume(). What should I use instead of this, or how to do it?

任何帮助将AP preciated。由于已为您的帮助

Any helps will be appreciated. Thanks already for your helps

推荐答案

给你:)

我也建议在这里看看: http://developer.android .COM /引导/主题/ NFC / index.html的了解文档,示例和code

I also suggest to take a look here: http://developer.android.com/guide/topics/nfc/index.html for more documentations, examples and code

<service 
            android:name="com.myexample.ServiceName" >
            <intent-filter>
                <action android:name="android.nfc.action.NDEF_DISCOVERED" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.nfc.action.NDEF_DISCOVERED" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="application/com.example.android.beam" />
            </intent-filter>
        </service>

更新:这是一个完整的例子:<一href=\"http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/nfc/ForegroundDispatch.html\" rel=\"nofollow\">http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/nfc/ForegroundDispatch.html

UPDATE: this is a complete example: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/nfc/ForegroundDispatch.html

这篇关于对于Android服务Onresume方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆