Android Studio update activity at 'Run' - java

At first, I'm new in programming of Android. And I have a problem/question.
Every Time i will click the 'Run' button to build and run my application on my device, my changes in the activity doesn't update/apply on device.
Is Anybody the, who know what i mean and know how to fix my problem.
I tried to find something in the preferences but i haven't found something.
At the moment i have to rebuild every time before run but this isn't a very nice way i think. There should be a better one.
Thank you for your answers.
Greetings

If you are using Instant Run, this is probably whats causing the problem - it doesnt recognise the changes you've made (at least that was the cause when I first had this problem). Just rebuild or clean your Project as already suggested - this will cause Instant Run to fully reinstall your application and not only install the new Patches. For me it occurrs quite often, I don't really see a pattern behind it but it's usually when I go to edit a completely different file/class, or when starting a new programming session.

Goto Build > Rebuild Project after that click Run again.
If it does not still updates your app I suggest to uninstall the app on the phone or in your emulator then Run again so a that a fresh APK copy will be installed.
Note: This is an odd thing when you are just running again without changing anything in your code.

The content should change, but I've noticed that with the latest instant run method, asset files typically don't get updated when you run it again. You could try setting up your preferences again and making sure you have updated your gradle, but if it's not updating you can simply kill the app before you run it again, either with the red stop button on Android Studio or though your phone.

Related

Android SDK - updating xml doesn't update app

I am completely new to Andoid Studio, Java, and app development in general.
With that, in order to learn, I downloaded Android Studio version 2.3. And, for my first project, I imported the accelerometer example from the sensors library. I opened it, poked around, didn't change/save anything, and ran/installed the app on my phone (simply clicking the RUN button from the SDK), and it worked fine ... I see the metal balls rolling across my screen.
NEXT, I figured I would make a small change to the project and see what I have to do to rebuild/remake the app, since I see 'make project', 'make app', 'rebuild', 'build apk', and 'synchronize' ... still not sure what all those do exactly.
So, my simple change was in the app/res/layout/main.xml file, and all I changed was
from:
android:background="#drawable/wood"
to:
android:background="#drawable/ball"
After this change, I went through every possible make, build, clean sequence I could think of, including the synchronize options within the different files. I've even disabled the instant run feature, uninstalled the app from my phone, restarted my phone, and restarted Android SDK. I even found a checkbox to "skip installation if APK has not changed" in the RUN/DEBUG configuration window.
What am I missing? Every time I RUN APP, it's as if no changes were made ... I get the same "wood" background from the original main.xml file.
Here is a link to the repo: https://github.com/googlesamples/android-AccelerometerPlay/
I checked the code and if you take a look to the AccelerometerPlayActivity you can see that the background of the view that acts as the activity content (SimulationView) is being set on this piece of code (in the onCreate method):
// instantiate our simulation view and set it as the activity's content
mSimulationView = new SimulationView(this);
mSimulationView.setBackgroundResource(R.drawable.wood);
setContentView(mSimulationView);
So, that's where you have to make your changes.

Running my new code runs my old code?

Somehow, whatever code I add to my program it does not run on my android device. It just runs my old code.
I am constantly deleting my app from my phone in the App Manager.
If I add new or change functionality the old code still runs.
I even delete complete blocks of code that should obliterate functionality. But somehow all the old functionality remains in the app after reinstall.
Simple example: On a TextButton click i shift some UI element by 200. This works great. When i delete the complete button listener it still works great but i guess completely by itself since the code should be gone.
I tried restarting Eclipse without luck.
This thing is driving me crazy. I was stuck for hours on some simple code and baffled why it did not run. Then I discovered my logs where not showing in logcat. Somehow, sometimes it does update the new code into the device since now i have a log on device resume but i deleted that at least 30 minutes ago and now it is still showing in my logcat.
Desktop app works as it should. I somehow have the feeling this happened before and over time this got worse, up to this point where i cannot test anything anymore.
So to be clear:
I add code to my app.
Run it from eclipse as Android application
No changes show up
Delete app from phone using the phones Application Manager
Delete a complete code block like the show() method that holds my complete stage
Run it from eclipse as Android application
App still runs as it was with the complete stage in tact.
-- edit --
Now I did not do anything to my code for a while and ran it. Now it probably took the code with the version with the empty show() method. However this already has been undone in the present. Could eclipse be stacking runs?
Check
"Project -> Build Automatically"
is checked. (Most likely your problem).
Also doing a
"Project -> Clean..."
tells the IDE to delete any previously compiled binaries and rebuilds them. (The APK file).
This could happen if there is an error in your code and you have selected run without warning when error in program exists. In such a case the last successfully built code would get pushed! As Lestat mentioned try doing a clean, if the project now shows up errors you have your culprit, else make sure your XML files are all proper.
Another check could be to see the timestamp of the last generated apk file in your workspace.
PS: There is a bug in eclipse where it doesnt save a file at time, a simple workspace restart fixes this.
Had the same issue - updated my code and yet the phone was running the old.
Tried Build --> Clean Project
Tried File --> Invalidate Caches/Restart
Now it works and recognizes the new code!
That said curious what #1 and #2 did behind the scenes??

Old copy of application appears on Android Emulator (using Eclipse IDE)

I'm using Eclipse and the Android plug-in for my Android phone development. I just worked through my first application from the "Busy Coder's" book and I'm having a persistent problem. Every time I run the example Java application, using a properly configured Android Run configuration that references the example project, the emulator starts (if not already started) and the application is seemingly deployed to the emulator. However, what shows on the emulator is not a reflection of the application's current state. Specifically, the example application I typed up should display the current time and then every time you click on the main app view area it should update the current time (via a Button object instance created in the constructor that has an onClick() handler). Instead, I see "Hello World" and clicking on the main view area does nothing.
It's as if some old copy of the test application is being pulled up. I even hunted down the strings XML file for the project and I did find a string declaration that was defined to "Hello World". I then changed that string to something else, rebuilt the project, and re-launched the application. But I still got the same "Hello World" display and still do not get any response when clicking on the main view area. I even tried shutting down Eclipse and the emulator and nothing changed, and also cleaning the project before a test run.
So, what are the usual mistakes a newbie makes that could cause this situation?
-- roschler
This happens to me occasionally but it is usually fixed by deleting the application from within the emulator UI.
After deleting the application from the emulator and reinstalling it I can launch the application using "Run". After this the application is updated every time the "Run" button is used.
Check the console to see if the activity is actually being installed and launched rather than being brought to the front when you "Run" the app.
If you launch in debug mode, the new build will always be installed in the emulator/device.
However, if you launch in run mode, you need to increase the version number in AndroidManifest.xml, or the new version won't always get installed.
Please see Android: Eclipse doesn't pushed new version of app to emulator from earlier today.
Hope this helps,
Phil Lello
By far the most common reason this happens to me is that I failed to notice that there was an error compiling the application so it didn't push the new version. Especially when my package explorer is obscured so I don't notice the red X.
Edit: one other reason it often happens to me is I have more than one emulator running or my phone or tablet plugged, and I accidently install the latest version to the wrong device without paying attention.
I open the manifest file in Eclipse, "touch" it by deleting and undeleting something, save it. This seems to refresh the APK for me.

a compiling issue using the Android virtual device

I have a question about the Android virtual device(avd)... as what you already know, that you can test your android application through avd in eclipse, and i'm getting a boring repeted thing with that.
each time I want to test my application and when I make a small change to my application, I have to run the avd again and wait for a long time till the application run(switch the device on and wait for the system to boot and then wait for the application to start,this takes approx. 15 sec)... as I said, each time I make whatever change to the program I have to go through these boaring time consuming loop :( ...
So, is there is a way to avoid these issue, and makes the avd run only for the first time and any changes can take effect quickly and only needed to restart the application without needed to stop and run the project again ??
I hope there is a way for that.
When you're done with a debug cycle, do you close the AVD? If you keep the AVD running, it should do exactly what you're describing.
If that doesn't work for you, a look at your application manifest may be needed.
Simply don't quit the emulator. Leave it running, hit Run (or Debug) in Eclipse, and if anything changed, the program will be uploaded to the emulator again.
Don't close the emulator. Keep it running and click debug again, it will run fast since it won't reboot. (The emulator will just re-install the app instead).

How can I run an app's source code that I got from the Android source code?

For all of you android devs out there that have the Android simulator running on your comp, you know that there are a few built in apps that are already installed on your 'phone'. I had an idea for an app that would utilize a function that is already being done in the spare parts app that comes already installed.
I went on to the android developer site, dug through the source code files, and found the spare parts app, and am now trying to set it up so that running it from eclipse on my machine actually runs the app in the simulator. In other words, I want to be able to make changes to and adjust some of the things in that app for my own needs. But it won't compile, because of a number of different errors.
How do I get that source code running on my local machine? Is there some special trick that I just dont know about? I thought that if I could get the source code than the rest would be easy, but it isn't being too easy.
Not knowing what the error is, it is hard to say. But there are some tricks. First, you want the entire spare parts app in Eclipse, not just the code you are interested in running. Second, right click on your project, and go down to the "Android Tools" menu. Then click on "Fix Project Properties". Do a clean on your project and hopefully that will help.

Categories

Resources