Start my android application *in the background* on boot - android

I am successfully able to start my Android app automatically on boot using BroadcastReceiver with an intent-filter BOOT_COMPLETED. In my onReceive method, I start the launcher activity for my application.
However, I don't want this application to be in the foreground on boot, but I do want it to be on the activity stack. Is there a way to still have the home screen show up on boot, but also have my application starts up. (I don't think I want to use a Service, because my application has UI.)

Decision on weather you should or should not use Service in appliction is independent on weather it has UI or not. All "third party" apps have UI, there is little use of application without at least 1 activity.
So in your case, just use Service.

Related

Is there a way to force app relaunch after it was killed by the Android OS?

Simple put: I want the app to relaunch (yes, from the launch activity, like if the user just tapped the icon button) every time Android kills my task because of lacking resources reasons.
The reason is that instead of managing everything that could possible go wrong after the app came back "from the dead", like NPEs, I want to start all over from the beginning.
I've searched for a "good practice" solution, but nothing came across.
Any ideas?
EDIT: I don't want to force the app back to foreground. However, if the user do it, I mean he brings it back to fore by his own free will, if Android killed my app because of resources purposes, I want the app to relaunch.
Sorry for not being clear previously.
Bringing your app to the foreground when it hasn't been explicitly opened by the user is considered a bad practice and discouraged. In fact, it won't be allowed in Android Q, except in a few cases:
Android Q places restrictions on when apps can start activities. This
behavior change helps minimize interruptions for the user and keeps
the user more in control of what's shown on their screen. In
particular, apps running on Android Q can start activities only when
one or more of the following conditions are met:
The app has a visible window, such as an activity in the foreground.
A different app that's in the foreground sends a PendingIntent belonging to the app. Examples include a Custom Tabs provider sending
a menu item pending intent.
The system sends a PendingIntent that belongs to the app, such as tapping on a notification. Only pending intents where the app is
expected to launch a UI are exempt.
The system sends a broadcast, such as SECRET_CODE_ACTION, to the app. Only specific broadcasts where the app is expected the launch a
UI are exempt.
Therefore, I would definitely recommend you to discard the idea.

Started Service stops if application is forcestop from download App

i made a sample android app,which starts a started service by calling startService(serviceintent).
it works fine,but if i forceQuit my application from settings>app>downloaded>force_Quit.my service stops and even destroyed is not called.
i studied for 3-4 days and know about start_sticky in StartOnCommand method.i am able to achieve all aspects of service.
I want to know whatever i am achieving that service stops and doesnot restart automatically even if started as Start_Sticky is normal behaviour according to android.Can i make it restared if user force quit my application.
my manifest is correct i uses process tag also.
if i forceQuit my application from settings>app>downloaded>force_Quit.my service stops and even destroyed is not called.
Correct.
Can i make it restared if user force quit my application.
No. Nothing of your app will run again until something uses an explicit Intent to start one of your components. Usually, that means that the user taps on your icon in the home screen launcher, though there are other explicit-Intent scenarios (e.g., GCM message).

android hidden app strategy

I'm trying to create an app "hidden" from applications list.
The way i though the user will start the app is through a Receiver listening for NEW_OUTGOING_CALL and intercept a particular number dialed.
The problem is that on new Android versions, this receiver will never be activated if the app never start once. (Starting the application from a BroadCastReceiver (NEW_OUTGOING_CALL doesn't always work)).
I can't figure out a workaround for this problem: the app launcher is totally hidden so the user cannot never launch the app, and the receiver would never be activated if the app will never start.
Is there any other strategy or workaround for hide and launch the app with some kind of secret action?
Create a activity with manifest file pointing it as the the Launcher activity and make it transparent and call its finish method in onCreate. User clicking on that icon will have no idea that the activity is opened. But why don't you show the About application kind of screen in the launcher activity?

Start Android application without launcher

How to start an application that has no launcher activity?
Story behind the problem:
I have an application that is basically a BroadcastReceiver that waits for a couple system intents like BOOT_COMPLETED. The problem is that as my application has no Activity, it doesn't get started and so it receives no intent.
Android 3.1 release notes mention that intent options can be overridden to start up applications but I assume it requires another active application to do so.
P.S. Write all the ways you know. ADB commands as well.
First piece of advice would be to make a very simple "Welcome to my App" Activity that could be run. Use it to show a splash screen, some advertising, or be a settings screen. That gets you around the "no Activity" problem.
As far as I know, you cannot have anything hooking into BOOT_COMPLETED until and Activity in your application has been run. So you need to have an Activity of some sort.

simple app which sends one sms without gui required

I want to write an app to send an sms from a shortcut on a home screen. That is all.
I just can't understand within the framework how I can write such an app. Here's what I've tried so far and what my ideas are:
I wrote an activity that sends an sms using SmsManager within the onCreate() however, this just keeps on sending messages even though the code is not in a loop. I realise I must be not be using an activity the way it's designed to be used. The android application fundamentals article says an activity is for displaying a screen or gui, but I don't need a gui. I just don't know what component I need to to use.
A service? no, because I don't need something running forever in the background.
An activity? I guess no because I don't need a gui.
I had an idea to create a broadcast receiver which would respond to a broadcast, so my sens smsm code would be in there ready to send when it receives the signal. But how do i send the signal from an app shortcut on the home screen? What would be the entry point of the app.
I'm just really confused, I've read the tutorials and the app fundamentals and searched forums and not found the answer. There's is just a big gap in my knowledge of the android framework that needs filling I guess, once it clicks I'll be fine but I'm just stuck right now.
Thanks people.
Service does not have to run forever. You can control how long it works in the background, you can even create Service that will shoot once and disappear. Suggestion:
from your shortcut (app icon) start Activity. That will be activity with translucent background. To achieve that skip line setContentView() and define theme
#android:style/Theme.Translucent
in your AndroidManifest.xml. This way you will avoid black screen flash at Activity startup.
from that Activity start Service and call finish() on that Activity
perform SMS sending (you already know how) from Service. Maybe, you do not even need Service, you can send SMS from the translucent Activity.
call stopSelf() from your Service immediatelly or after some short timeout (wait for SMS sending result).
All described can be done smoothly through Widget framework. In that case you can even have custom button user may press on. So, that would be another approach.

Categories

Resources