Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I debug an app without reinstalling it?

I have an Android app that needs to perform a certain task one time after it's installed, and then never again. It uses SharedPreferences to record that it's performed the task successfully.

In order to test this behavior, I run the task via Android Studio on a real device, connected over USB. The problem is, every time I run the app via Android Studio, it reinstalls. As such, it seems to lose its persistent memory (SharedPreferences).

It makes sense that the app's SharedPreferences should be wiped when it's reinstalled. But how do you run an app in the Android Studio debugger without reinstalling it and wiping the persistent memory? I looked at the Android docs for running an app from Android Studio, and from the command line, but none of them seemed to offer a way to run it with a debugger connected without reinstalling.

One option I see to accomplish this would be by closing and re-launching the app from the device itself, and then attaching the debugger in Android Studio to the app's process. But this would mean the debugger misses the first few seconds or so of the process's activity. My app's task gets done in the first microseconds. I should still be able to view the logs from those first few seconds, but not to have full debugger control.

Any ideas?

like image 910
LarsH Avatar asked Dec 05 '25 03:12

LarsH


1 Answers

if you directly run app from android studio from same machine it will not reinstall it updates the app so your sharedpreference will not wiped it remain same. For more info about sharedpreferances http://developer.android.com/reference/android/content/SharedPreferences.html

for debug from first step you can use debug option which run app directly in debug mode (shift+f9) https://developer.android.com/tools/debugging/debugging-studio.html

like image 126
Pavan Avatar answered Dec 09 '25 00:12

Pavan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!