Android emulator, how can I control 2 applications simultaneously? - android

Is there any way of running 2 (or potentially more) applications on the emulator at the same time?
I have an application that obtains its data from another application, therefore I want to modify data in application A and then see how application B handles it.
I'm intending to have some kind of "slider" on application A, therefore I need them both to be running at the same time to see the "slider" on application B update.

You can't have UI threads of two applications running at the same time, but if one of your apps has a background service, that can be running while the UI thread of the other is active. This service could put a notification in the status bar to signify that the data has been updated (actually, I think it's now required that a background service have something in the status bar anyway).
I believe you can also create a "toast" pop-up notification from a background service.
If it's just for testing, your background service can also write messages to the logs which you can see with logcat.

You can use the emulator like a normal phone, so you can run as many apps at the same time as you want. When you say "running", are you talking about "debugging"? You can install any number of apps using adb install, or by just running it through Eclipse. Running a new app won't stop the previous one (besides, you can always go to the app menu and start your other app).

Related

Android Oreo: Is there any way to auto - start the application on mobile reboot?

I am developing an application for a business entity. That application should run in the background in every employees' mobile phone. Employees are mostly salesman. The application basically detects location changes and suggest the salesman where they might visit. A kind of reminder application. It also lets other salesmen see where are their teammates.
Right now I am using a foreground activity and it works fine till the system forcefully doesn't kill the service or the phone doesn't reboot due to manual activity or battery discharge.
Ones the application is closed, as of now, the managers in the firm needs to call salespeople to turn on the application once, as on application start it automatically turn on its foreground service. But this is really an extra burden on the management team which can be automated.
I am ok to have any settings based or code based solution. One solution is to root the phones of salespeople and install some extra utility app or write the code based on root APIs, but this will be too much for this simple task.
THe permission RECEIVE_BOOT_COMPLETED was not added properly in the manifest. After adding the permission it worked calmly. In on receive method of the broadcast receiver, I am starting the foreground service.
At the moment, the best way is to use WorkManager https://developer.android.com/topic/libraries/architecture/workmanager/ Yes, it still alpha, but works very good.
From other side, you could work on automating the task "managers in the firm needs to call salespeople to turn on the application once". I mean, an app/backend could automatically call the salesman (with some pre-recorded message) or send SMS to them.

Android: launch any activity to start in the background?

If I'm writing my own Android app, I know how to structure it as a Service so it will start running in the background.
However, is there a way to launch an existing app (for example, any random .apk from the Play Store) so that it starts up in the background, without its screen taking over the display?
Alternatively, I'd be willing to launch the app, force it into the background, and redisplay the window of the previous app (whatever it might have been) that was running in the foreground. I don't know how to programmatically put the current app in the background and then determine the previous app and bring it back to the foreground.
I'm willing to do this any way possible: via Java, via one or more command-line utilities, via a Tasker plugin, via an Xposed module, or whatever.
Thank you in advance for any pointers to docs or any suggestions.
I discovered that the #0 entry of "dumpsys activity recents" gives the currently displayed activity ... at least on my rooted Marshmallow device. This gives me what I need.

Android service, need a service that keeps running

I am a beginner in Android development. I want to build a service that once started, must keep running.
Step 1.) Once user will install the app give some input, service will start. (i'll use IntentService)
Step 2.) Now user moves to other app/close my app. I want to make sure Service should keep running and processing/saving info with current timestamps.
Questions:
1.) How I make sure that the service keeps running/saving data even if user returns after say, 1 month on my app.
2.) I read that every app is a new user and separate VM is provided by the Android, question is when an app is considered to be closed?
3.) If my app closes, related services will also close then?
1.) How I make sure that the service keeps running/saving data even if user returns after say, 1 month on my app.
Once user installs app, you can start STICKY service but make sure you inform the user as well as Android OS by making it run on foreground with on going notification. it will help your service to run for long time without being killed by Android OS.
1 month is long period, user may reboot the cell in between. and you will need to restart your service. so you should register for reboot complete event .
2.) I read that every app is a new user and separate VM is provided by the Android, question is when an app is considered to be closed?
There is no condition like considered to be closed.Actually, when user installs app, it is by default in stopped mode, it gets activated when user opens your app for first time. and application can go back to stopped mode again whenever user force stop your app.
3.) If my app closes, related services will also close then?
If you are considering that app is considered as closed when user don't use the app,your service won't close unless Android OS kills it in low memory situation.you may make it foreground as suggested earlier to convey Android OS that you are doing important things,nothing is wrong,so kill me only at last when you don't have any other options left

how to keep application in running mode when create and launched in android?

I want to keep android application run in background not in foreground when it launched. For Example, like Android Settings and Android Keyboard. Only Running Process List in display this application. Actually, this application is running in background and user can't display it in foreground.
No matter what you want to do with your app, if you want it to run in the background and not getting destroyed when it isn't displayed anymore, you have to use Service.
This is the Android Developers site explaining it:
http://developer.android.com/guide/components/services.html
And this is a nice tutorial:
http://www.vogella.com/articles/AndroidServices/article.html
If your code doesn't work with a service, it's probably not the service's fault, but your code's, and you should post another question precisely explaining your problem with it.

Run service and activity in different processes in android

I have the following scheme in my application.
Broadcast receiver listen for an BOOT_COMPLETED action and sets repeating alarm.
Alarm starts a service via PendingIntent.
Service checks for some data by internet, and when new data are available, shows notification, which is runs an activity, when user select it.
All is working perfectly except one thing. When i close the app from Task Manager on my device, process is killed and my alarm no more works. So the process is stopped until next restart of device.
Setting android:process to different for the service and activity does not help. Debugger shows me that we have two different processes, but closing an app from the task manager kills both processes.
I have created two different applications, one just an activity, and the second one for broadcast receiver and service.
In that case all is working as i need. But now i have another issue. Two .apk files. I have tried to find a solution to merge two apk's in one for Market, but looks like its impossible. Ask user for installing two apk for one does not good idea i think.
So my question is how i can solve this?
When i close the app from Task Manager on my device, process is killed and my alarm no more works. So the process is stopped until next restart of device.
This is a good thing. The user, by killing or force-stopping your application, is saying "I do not want you to run again". Developers should respect their users wishes.
So my question is how i can solve this?
Treat your users with respect and allow them to force-stop your app if they choose. You can re-enable your alarms on the next manual run of your application.
You can also detect if they did this, by having your AlarmManager-triggered code keep track of when it runs -- if, the next time the user manually launches your activity, you determine that the alarm code has not run in far too long, that indicates the user force-stopped you. You might use this information to suggest that the user go to your PreferenceActivity and change how your alarms behave (e.g., run every 24 hours instead of every 10 minutes), so that the user does not feel the need to force-stop your application.

Categories

Resources