• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Running Application in the background

 
Ranch Hand
Posts: 1015
11
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having a lot of success working with a tutor on preply.com to learn how to write an Android Application.

I want the application to have these features:

A) Wake up every fifteen minutes on its own.
B) The Application Icon should always be available on the desktop after it has been installed.
C)  The user may open the application at any time and it will stay open until the user closes it.
D) The application should only show in the multitasking application area when it wakes up on its own and that will probably only be for a few seconds.  It will close the GUI on its own.
E) The application should show in the multitasking window when started by the user and it should stay open until the user closes the application.
F) There will be a switch in the application that determines how often the application should open and close on its own.
G) When the application opens on its own it will close the GUI Application after processing for the few seconds it needs to do its work.

The reason I want to have it hibernate, do work and then sleep are:
1) To save battery.  I don't know if this makes a difference.
2)I  don't want the application showing as a choice in the place where it shows all of the running applications unless it is running. either by the user starting it or when it wakes up on its own.

I have heard something about being able to communicate with the internal Android O/S,  but I don't know anything about it yet.

I couldn't think of a clear way to write this post in a less verbose way.

Thank you,

Kevin




 
Rancher
Posts: 5116
38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kevin,
I wrote some Android apps years ago that do some of what you are looking for,   They are written in Java.
I uploaded them to Github: https://github.com/NormR?tab=repositories
You are welcome to any of it.

The Wakeup app runs in the background checking the device's orientation to detect when I have moved it from horizontal to near vertical when it turns on the screen.  My tablet's power on switch had gone wobbly and was not reliable, so I wrote this app to turn it on when I lifted it.  I still use it with my newer tablet with an ok switch.   It sleeps during the night to save battery.

Another app that runs in the background on a schedule it the BatteryLevelWarning app.  I have several tablets that I use occasionally and don't always power off.  The app checks if the battery level is  below a limit and then broadcasts a warning message in English.  It has scheduled times to do the check and sleeps during the night.

Norm
 
kevin Abel
Ranch Hand
Posts: 1015
11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Norm,

I looked at XML.  I'll check the Java later.  It looks like what I'm looking for.    

I see many people on-line missing phone calls.  Then they check settings and see that the ringtone volume went to zero.   Nobody knows why.  It could be the O/S, a virus, another app accidently or purposely doing it, the user pressing the volume down button and not knowing they did it.

So, I'm working on an app that wakes up once in the while and sees if the ringer setting dropped and restores it.   So far,  I can check and set the ringtone volume setting from my Android App.  I don't have much else working.

I don't know if closing and opening the app occasionally will save battery or if having the listener in my app always waiting for something to change the ringtone volume is just as good.

My plan is to post the code on git and also learn how to publish it in the Play Store.

Thanks,

Kevin
 
kevin Abel
Ranch Hand
Posts: 1015
11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After the last post I became curious to see the code.  

It is waaay more advanced than what I have so far.   The Java code is easier to read than Kotlin.  I don't know the advantage of Kotlin yet.

I'm working with a tutor on preply.com to learn how to do this.  I'm probably retired unless I get some remote QA Automation or even manual testing work.  I'm learning Android development as a fun hobby.  

Thanks,

Kevin

 
Saloon Keeper
Posts: 28701
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kevin, I think most of what's on that list is standard Android behavior. Also, the android lifecycle is designed to minimize energy usage, so you shouldn't generally have to do anything special.

Things to be aware of are that there should be a watchdog service that would wake up your app while otherwise letting the Android system deal with it. Also, don't take over the display by main force. It's rude. One of the preferred alternatives is "toast".

One caveat about looking at any Android code older than 6 months is that Android is not stable like general Java is. It's more like Microsoft Windows, except with better deprecation management. I think that, for example, the threading/job APIs have gone through about 5 generations in quick succession. It has finally stabilized, I think, since it can use the newer Thread resources of core Java.

And in case you weren't aware, Android, like JavaScript uses an inside-out GUI threading model. Regular Java runs apps in a main task and has a separate child thread to run the GUI. Android runs the GUI in the main thread and things like database operations have to run off child threads. Having done both, I find this to be a real pain. And, incidentally, that's a lot of what Kotlin is intended to mitigate. Plus, of course, keeping Oracle's lawyers at bay.
 
kevin Abel
Ranch Hand
Posts: 1015
11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim,

Thank you for the information about Android.  I'm having fun time learning.  

Kevin
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kevin Abel wrote:I'm having a lot of success working with a tutor on preply.com to learn how to write an Android Application. . . .

Hey Kevin,

It sounds like you have a clear vision for your Android app, and it’s great that you're making progress with your tutor! Here are some thoughts on your requirements:

Wake Up Periodically: You can use a Handler or AlarmManager to schedule the app to wake up every 15 minutes.

Desktop Icon: Ensure that your app is set up correctly in the manifest file, which should automatically place the icon on the home screen after installation.

Persistent Open: You can manage the app's lifecycle in the onPause and onResume methods, keeping it running in the background.

Multitasking Behavior: To control visibility in the multitasking area, use Activity flags in the intent to control how the app appears. You might consider using a foreground service for tasks that require running in the background without showing a UI.

Switch for Frequency: Implement a simple SharedPreference to allow users to set how often they want the app to wake up.

Hibernation and Processing: Utilize services that can run tasks in the background without needing the UI active.

As for battery saving, hibernating apps can help conserve power. Communicating with Android’s OS can be done through its various APIs, allowing you to access battery stats, manage background processes, etc.

Your approach to keeping things efficient and minimizing unnecessary resources is solid. Good luck with your app development!
 
kevin Abel
Ranch Hand
Posts: 1015
11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Munnou Roberts wrote:Your approach to keeping things efficient and minimizing unnecessary resources is solid. Good luck with your app development!



I appreciate your technical ideas and support.  

I don't know about many of the topics you and Norm are speaking about yet.  I started with a Description Document of what I want the app to do.

I found my tutor on Preply.com and she is great!   I also have a Mandarin Chinese Tutor and at one time a Java Tutor.  All are wonderful.  

You seem to be new on Code Ranch.  Although I have only met one user in person, I feel as if I have a lot of friends. I hope you stay around this board.  

I was a QA Automation Developer for about 30 years.  I'm retired unless I get an offer for a fun project that can be done remotely.   I lost my interest in constant struggling of learning technology.  Now I prefer to have some knowledge and then work with an expert to create an application.  It's a new approach and I have no client so I'm having a lot of fun.

Kevin

 
reply
    Bookmark Topic Watch Topic
  • New Topic