In my app I wrote mechanism which lets return to the activity whet the application is suddenly removed from the device memory. Sometimes it happens eg. when the phone rings and there is not enough memory for phone application and my app. After the phone app ends the system call quite new process for my app and opens this activity which was closed previously.
I hope the mechanism I wrote works fine but I don’t know how to test it. I work in android studio.
So the question is how to simulate the process of killing and removal the application from system, and calling back my app process and activity.
fire this by cmd
echo 'am broadcast -a com.android.vending.INSTALL_REFERRER -n "package name/path of reciver" --es "referrer" "utm_source=test_source&utm_medium=test_medium&utm_term=test_term&utm_content=test_content&utm_campaign=test_name"; exit' | ./adb shell
Related
Hi every one I'm currently working on a project which i need to monitor app behavior on emulator boot (i have a broadcast receiver which is being triggered with boot complete) the problem is the logcat shows process is terminated when you restart the emulator.
any idea how can simulate the boot and see logs in logcat???
On your emulator, go to Settings -> System -> Developer Options. Under 'Debugging' go to "Select debug app" and find your app, then underneath that option enable "Wait for debugger". Now when you reboot the emulator, the dialog to attach the debugger will show asking you to manually attach your debugger. Once you do that, your app will start and the receiver will get triggered.
Android studio emulators restart by long-pressing the power button and choosing "Restart". If you want to simulate the request instead you can use the following command:
adb shell su root am broadcast -a android.intent.action.BOOT_COMPLETED
This is my scenario
Launch the app and perform some steps
Hardclose/Forceclose/Kill the app from memory/Should not run in background
Launch the app again
Perform some steps
Assertion step
How to achieve this?
I have tried the following methods
resetApp() - it uninstall the app and install app again.
closeApp() - it just close the app but app is still running in the background.
adb shell am force-stop <packagename> - it just close the app but app is still running in the background.
But for my scenario it should delete from the background and app should not uninstall in Android in the same test (middle of the test).
You can try it, I think it will serve your purpose, use below line from where you want to launch the app again
Activity activity = new Activity("appPackage", "appActivity");
driver.startActivity(activity);
Try below code and add this to the capability :
capabilities.setCapability(MobileCapabilityType.NO_RESET,"false");
It should work as per your requirements.
I have an apk which runs only on background. I want it to start itself every X seconds.
I can do it from terminal with sh command:
#!/bin/bash
while true
do am start --user 0 -a android.intent.action.MAIN -n com.xxxxxxx/.MainActivity
sleep 20
done
But after reboot it stops running itself automatically. Besides, I don't want to use sh command everytime. So I decompiled the apk with apktool. What do I need to add to make our app start it self every x seconds?
p.s. I know that if I save the commands as sh file into etc/init.d/ it'll be persistent but I'm trying to learn how can we add it to source.
What do I need to add to make our app start it self every x seconds?
You need to schedule it with the AlarmManager. You can find more about that here.
But after reboot it stops running itself automatically.
You need to register a receiver for android.intent.action.BOOT_COMPLETED for you app to be invoked after boot. You can find an answer for that here. When your receiver is invoked, you can then again schedule your app for restarting.
When I run my application many lines appear in the logcat but only one error:
E/art﹕ Failed sending reply to debugger: Broken pipe.
What does it mean? And how can I fix it?
Explaining the error:
E/ART: Failed sending reply to debugger: Broken pipe.
What is E/ART?
ART is the Android RunTime. This is the bytecode interpreter on your Android phone. The E simply indicates the logging level of ERROR.
What is "sending reply to debugger"?
Debugging on the Android phone is done using the adb (Android Debugging Bridge). The adb process runs on your dev machine (your laptop or PC) and a daemon runs on the Android device (i.e., the emulator or handset).
What is a broken pipe?
Your dev machine and the Android device communicate like a client server and a broken pipe means that the communication has become invalid. For instance, the client (the Android device) is trying to send a reply to the server (the adb process running on the dev machine) but the server has already closed the socket.
How to fix it
First make sure your app is building correctly by performing a clean/rebuild.
Then if you are running your app using USB debugging on a real phone then you can often fix the problem by unplugging the USB cable and then plugging it back in to reestablish the client/server connection.
If this doesn't work, you can disconnect the USB cable and (stop the emulator if necessary) and close Android Studio. This is often enough to stop the adb process. Then when you open Android Studio again it will restart and the connection will be reestablished.
If this doesn't work, you can try stopping the adb server manually using the instructions in this question. For instance, you can try opening command prompt or terminal and going to the sdk/platform-tools directory and typing:
adb kill-server
adb start-server
You can do the following:
Kill emulator and Android Studio
Open Android Studio and "Rebuild" that basically deletes the build folder and recreates it.
I had a breakpoint in a return statement, when I removed it everything ran as it should. So give that a try too (removing all breakpoints).
killing the "adb" process helped me recover from this error. Just try restarting the adb.
The Error comes because of not getting the actual data or class. Use Android Monitor with Log level Error and no Regex filter to check error.
Hope you will get actual error.
I had this error when I made a mistake with a object type (img response) in my model class, while I tried to get response from my Url in Android. And when I fixed it the error gone
Check the file name colors in res folder
if name is color then replace with colors
I think you need to move your color declaration out of strings.xml and put it inside of colors.xml
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="myColor">#ccff00</color>
</resources>
I have an Android app published on Google Play. When the app is launched for the first time (it is done by storing and checking boolean flag "FirstLaunch" in SharedPreferences), it launches a Service which will be launched once a day (=every 24 hours using AlarmManager).
For the sake of simplicity let's say that this service just shows a Toast with "Hello World!" when the time comes.
Let's assume that there is a user who downloaded and installed my app from Google Play.Let's also assume that I have changed some code in that service (e.g. changed the Toast from "Hello World" to "Hello Universe!") and updated the app on Google Play.
If that user updates my app, will the service start showing new Toast text ("Hello Universe") once a day, or will it still show the old version ("Hello World")?
Generally speaking, if I am changing the code of a running service, do I need to relaunch it programmatically in my app, or will Android itselft change/switch its code to the new version?
Android services runs as part of your application process, when the process is terminated your services will be terminated as well (it will be restarted if its start mode is sticky which will restart the whole process), so when the user updates your app a new process will be started with your new code
If Android updates an app (through the PlayStore of course),which you are currently using, it gets terminated. Services get terminated as well. So if users of your app receive their update, their service gets terminated and restarted, if thestartmodeof your service issticky or it gets restarted by your app.