Sex, Lies and Renamed Activities
By Bobby Gill on April 1, 2011 / 1 Comment
…when you get an ActivityNotFoundException and you are certain that you updated your AndroidManifest.xml file
I think the hardest aspect of learning a new framework is running into these stupid little issues that leave you stumped for 4 hours, all because I lack the tribal knowledge to instinctively know whats up.
So let me tell you my story with Android yesterday. I was getting cute with my activity structures and decided to rename them to adhere to a common naming pattern. I should have known better than to rename Activity classes, especially when they are referenced in XML. But you know what, all of you little nerd-bitches have such big hard-ons for Eclipse, that I thought its refactoring tool would be up to the task.
I had an activity named “Login” and used Eclipse to changeits name to “LoginActivity”.I thought all was well after the change, and proceeded to debug.. (you see that is called foreshadowing because we all know what happens next…)
ActivityNotFoundException: cannot find activity ‘LoginActivity’ ….make sure its referenced in the AndroidManifest.xml
Ok, that’s not bad. I get it. I go to the XML file, and I check it, but wait a minute. The Eclipse IDE had already gone through and already renamed the <activity> node to point to the new LoginActivity name.
<activity android:name=”.activities.LoginActivity” android:label=”@string/app_name” />
Hmm. So I re-ran the test, just to make sure it wasn’t some race condition on the saving of the XML and the launching of the APK.
Now I start to be bewildered. Google, Bing, Cheggit, all had no answers for me. I have changed the AndroidManifest god damnit! I can open the file in the IDE and its right!
So I think maybe it’s the fact that the APK wasn’t being updated either locally or pushed to the phone. After deleting the APK and forcing a rebuild and deploy:
I think then maybe it has to do with the namespaces and with the “.” not being present in front of the name value. So I try every permutation/combination of “.” with the LoginActivity and every other activity. After each try:
I then decide to remove all values from the AndroidManifest.xml file. All of it. I rebuild it from scratch using the wizard at the front. After a recompile and debug:
*head smacks desk* . Finally as a last resort, I delete everything out of my AndroidManifest.xml file and re-run.
Wait a minute. That doesn’t make sense. There should be no ActivityNotFoundException, at least not for the LoginActivity class since it shouldn’t be launching as there were no activities defined in the manifest file at all. In fact, I would have expected the Android equivalent of a “no start point found” error. But it appeared the app was launching just like it was before.
Something is up, who can I trust? The Eclipse IDE or the Android application? Neither I decided. So I open up Visual Studio, crack open the AndroidManifest.xml file and what do I see…
<activity android:name=”.activities.Login” android:label=”@string/app_name” />
The exact same file as I had began with before I did my rename of the LoginActivity! For some reason, the Eclipse IDE was letting me edit the file , make changes and save the AndroidManifest.xml file, but the file on the file system wasn’t being updated.
Really?! That’s what caused me to lose 3 hours of valuable productivity?!
I don’t want to sound like a hater, but come on, when was the last time Visual Studio did that to you? I mean VS does a lot of naughty things to me, but lying to me about saving a file has not yet been one of them.
Get the latest from the Blue Label Labs' blog in your inbox.
More in Development
Houseparty App: From MVP to Household Name
Unless you’re building a niche app for business, the ultimate goal for…
Differences Between Native, Hybrid and HTML5 Apps
With Blue Label Labs’ extensive experience developing apps, we can assist with…
How COVID-19 is Affecting Data and AI Algorithms
Since the world was asked to lockdown, we’ve seen some dramatic shifts…