How to prevent Android Studio 2.0 from running on same device - android-studio

With the new update of Android Studio, whenever I rebuild my app, it always launches it on the same emulator/device. In order for me to switch devices, I have to shutdown the emulator/disconnect the device, so that it brings up the device selection screen.
Is there any way around this?

For me I had to press the red stop button in order to stop the "instant run" mode which automatically runs your app on the same device.
Once I press the stop button I can run the app again and it will bring up the device chooser dialog.

Just do this:
Select this menu:
And then uncheck the "Use the same device.." option:
Uncheck thi option:

Related

Android studio does not show 'Lenovo K6' phone in run window

I have "Lenovo K6" phone. I already made a project, when I press run button, android studio does not show my device on that window, what will be the solution?
open your settings, go to about section and look for build number and tap it repeatedly till you see a toast saying developer mode enabled.
Then, search for the developer option in settings. inside there, you'll find an option saying something like "enable USB debugging" turn that on.
Then, connect your phone through USB while android studio is running. the screen might show a prompt asking for "allow debugging?" or something similar.
now try again.
If you still don't get it, search for how to enable USB debugging on android.
allow USB debugging in your mobile, to allow the USB debugging you need to click on Build number 5 to 7 times on your mobile phone settings then go to developer option then enable the debugging.

Android Emulator got stuck at "shutting down"

The emulator in my android studio keeps showing "shutting down". I try closing it and run again, restarting my mac, but nothing worked, each time I run it, it shows "shutting down" again. even though I can see actions running below (very blur)
Click on Tools
Click on AVD Manager
Click on the dropdown arrow next to the AVD which is stuck
Click on cold boot now
This issue occurs when we forcibly exit an unresponsive/stuck AVD. AVD manager saves the state before it is forcibly exited and on the next start it continues from the unresponsive/stuck state. This is useful when we need the AVD to boot up quickly, however if you want to disable this feature entirely then follow the steps below:
In the AVD manager, click on the pencil icon
A new window will pop up. Click on show advanced settings
Scroll down to the emulated performance section
Next to boot option, select cold boot
open AVD Manager Dialog from top right corner
go to your emulator
click on the last icon on the right which is a drop down button
Click wipe data
Important Note: this will delete all data on that emulator and give it a fresh install again and might solve your problem
If that didn't work then check that you have enough rams to run both the emulator and the android studio.
I run my emulator with cold boot by command line
cd C:\Users\<your_user_name>\AppData\Local\Android\Sdk\emulator
emulator -list-avds
emulator -avd <your_adb_name> -no-snapshot-load
If the cold boot or wipe data does not work, you can try deleting the lock file. Then quit the emulator, and restart it.
In my case, AVD Manager prompted me to delete the following files, I did it, and the problem was solved.
If it shows "AVD *** is already running etc." then just connect any mobile device that after enabling debugging mode and run your app in a physical device instead of an emulator then
Click on Tools
Click on AVD Manager
Click on the dropdown arrow next to the AVD which is stuck
Click on cold boot now
First of all:
You have to close the window, or tab of your Virtual Appliance.
With this you get Android Studio to standby the Device and unlock the ADV (Android Virtual Device) files, so you can manipulate the virtualization.
Maybe you have to wait until Android Studio kill the process. If Android doesn't do this automatic, you will have to close Android Studio and delete C:\Users{YOUR_USER}.android\avd{YOUR_DEVICE_NAME}.avd and within this folder delete all files and folders with extension .lock to stay secure before start again Android Studio.
After that:
Just open the Device Manager, and click on the down arrow in the Actions section for your device, and select Cold Boot Now. This reload the Virtual Device without start or open any program.
Finally:
If Cold Boot Now worked fine, now you can run or debug your application to check that it functions perfectly. Without the device continuing with the problem that the system is still stuck/frozen.
And also you do not need to do a Wipe Data, so you do not delete the data of your application, since you can have any internal database in SQLite, which has the changes and advances that you have been implementing or creating during the development of your application for its operation.

UWP launch on screen keyboard on button click

I am developing one UWP app where I want on screen to be launched on button click. I want to deploy app in surface tab.
Keyboard is getting visible in Tablet mode when text box is being focused but not in desktop mode.
In UWP System.Diagnostics.Process.Start(".exe") is also not permissible.
So ultimately I am thinking to use button to launch on screen keyboard.
Is there any way to do that?
Kindly helping me out?
It seems you can run .exe in UWP using FullTrustProcessLauncher. So run osk.exe to open on-screen keyboard. Check the above link for more info.

Android Studio 2.0 launch APK on another device

Since Android Studio 2.0 and its reworked "build / run" mechanism, I can't "launch" an APK on a second device anymore. Once the APK has been loaded on the first device, I can't choose to launch a build to another device.
"Run" will target the current device
"Re-run" will stop the application running on the current device and upload it to the "second" device.
So my question is : "How can I launch a "second" build targeting a different device than the first device I builded on without terminating the first process ?"
Sorry for my bad english, this is not my native language.
If you click the stop button (Red Square), the Instant Run is deactivated. Then click the Run button the list of devices appears again.
The drawback is that when you click on the stop button the application is killed on the current running device.
We need a way or a shortcut to bypass Instant Run
Disconnect the device, click on the "play" button. Android Studio ask you now where to run the app.
Connect your device and select it.
On of the helpful method I found through which at-least you don't have to disconnect your already connected device to run the app on another device.
Click on the arrow down icon near to run option and select Edit Configuration.
It will open Run/Debug configuration dialog box, uncheck the checkbox "Use same device for future launches".
Next time when you will hit the run button, Android Studio will ask you to select the device.
When you deploy to your first device, make sure you have not selected to launch on the same device for future launches. Untick in your case.
Should you have already had this option on, and it is running on the same device, then unplug the device it is launching on, or turn off the emulator.. and it will ask you which device you now want to launch on.

How do I stop app in Android Studio

I must be missing something totally obvious, but I can't find a simple way to simply stop an app from running. I'm running it on my HTC One.
I first tried toggling the green run arrow. Didn't work.
I found a "Terminate Application" circle in the lower left of the window. That doesn't seem to do anything when you click it. It seems to be grayed out, non-functional. Screen shot here
http://www.screencast.com/t/VLTOzPQ7
So, I closed the entire project. That worked, but also the entire Android Studio closed instantly. Then reopening Android Studio failed (stack dump). Then reopening again worked, but it took 30 minutes to load my project.
To stop the next time, I turned my phone off, then closed the project. That seems to have worked better, since it took me to the Welcome to Android Studio screen and invited me to open or start a project.
Maybe there's an easier way to stop an app? I see the same question on this forum but no solutions.
The Android Studio controls you are trying to use only work if you are running your app in the emulator. There are a few ways to do this when you are using an actual device or VM (e.g., Genymotion):
Use the UI of the phone to Force Stop the application. This is done in the Settings->Apps menu.
Use Android Studio's terminal window or the host's shell and issue the command:
adb shell am force-stop <package-name>
Open Android Device Monitor (green "Droid" icon), select the process under the Devices tab and click the Stop Process button (stop sign icon). This is basically the GUI way of doing #2.
You need to select the process you want to terminate (ex. com.myname.myapp) then click terminate application.
Since the application is running on your phone, you need to end the application process on the phone. When you do that the application would be shown as terminated on Android Studio.

Resources