How to run android program without open the app?

后端 未结 3 710
忘了有多久
忘了有多久 2021-01-28 04:56

My app can be opened by NFC, and then use the information in the tag to do some processing, the processing is around 5 seconds.

If my app is opened by NFC, I don\'t want

相关标签:
3条回答
  • 2021-01-28 05:10

    In your manifest.xml you can specify set the following theme for your activity:

    android:theme="@android:style/Theme.Translucent.NoTitleBar"

    This makes your activity invisible (if it's empty).

    0 讨论(0)
  • 2021-01-28 05:19

    If I am getting you right, you want to start some operations in the background as soon as the app gets started via NFC. The point is that, as soon as you actually start your app and the onCreate method of an activity gets called, your application will enter foreground and will become visible.

    Assuming, you do not necessarily need to start an activity but some process in your application via NFC, the best solution is to outsource the code that should run without bringing the app into foreground into a BackgroundService. Set up a BroadcastReceiver onto the NFC-events you want to get informed about. As soon as it receives a notification, this receiver can then start your background service.

    EDIT: grexter89 is right, I am sorry for my non-realizable hint. The intents provided by an NFC event can only be processed within an activity! Well, I am sure this is not the answer you want to here but I guess that this limitation is based upon some security/privacy issues. If the approach mentioned above was possible, NFC events could start processes without the consent and confirmation of the user as soon as the user, maybe accidentally, gets into contact with an NFC field. This is the use case you would like to use for your application but, however, these circumstances could be easily misused.

    Regarding these points you should rethink if you actually want your activity to be invisible. Given the activity-only-limitation from Google and the above reasons (=> activation by accident, lack of user awareness) I would implement an approach with a visible Activity that shortly displays a hint to the user.

    0 讨论(0)
  • 2021-01-28 05:19

    Put the line setContentView(com.airbutton.R.layout.test); inside an IF to validate if you should display it or not. Remember that activities can exist without an UI.

    0 讨论(0)
提交回复
热议问题