title: How can I debug an app without reinstalling it?
body: <p>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.</p>
  
  <p>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).</p>
  
  <p>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 <a href="http://developer.android.com/tools/debugging/debugging-studio.html#attachDebug" rel="nofollow">Android docs for running an app</a> 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.</p>
  
  <p>One option I see to accomplish this would be by closing and re-launching the app from the device itself, and then <a href="http://developer.android.com/training/basics/firstapp/running-app.html" rel="nofollow">attaching the debugger in Android Studio to the app's process</a>. 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.</p>
  
  <p>Any ideas?</p>