Android Wear App persistent in the Forground

I am writing some android war stuff currently. I do not want to go into detail what it is (uh oh, secret Smilie: ;) ) but one thing I have to do for it is that I need to constantly gather some data at start. Now for this the easiest solution is to just have an app running in the foreground doing the gathering. So, I did make that: Making a small wear app. Initiate the data gathering, test the code. I thought I am almost finished.

Then came the surprise: My full-screen App was constantly killed. Now the Android Documentation says: “The system enforces a timeout period. If you are displaying an activity and user’s don’t interact with it, the device sleeps. When it wakes back up, the Wear home screen is displayed instead of your activity. If you need to show something persistent, create a notification in the context stream instead.” (Android Developer: Creating Wearable Apps)
Several people report similar problems, now in the recap I only found this example: Stackoverflow: How can I find what is stopping my activity.

The problem is, as the people on stack overflow in this post suggest, that they make a solution which completely changes your architecture: Instead of having one simple app running in the foreground for a while, insert interactive notifications into the context stream.

However, this is NOT the solution for a simple foreground application. For that go to the main activities (f.e. rect_main_activity.xml) layout, and add <Layout android:keepScreenOn="true"></Layout> to the root layout element. That means f.e. the RelativeLayout or LinearLayout nodes, so usually you have to add it twice, for the round and rect layout. That is it, really. This solution worked quite robust for me.

Category(s): Uncategorized

One Response to Android Wear App persistent in the Forground

  1. What I almost forgot: You should really watch this video as an itroduction to wear developement I found out: https://www.youtube.com/watch?v=sha_w3_5c2c#t=1241

Leave a Reply