Blank Activity vs Empty Activity - android

Does anybody know why the blank activity in the latest version of Android Studio now includes two .xml files for each Activity? My instinct is to use Empty Activity and continue doing things "the old way" but I'm wondering what Android's "bigger picture" is with these changes? Is it wiser to develop any future applications using this new Blank Activity format? Thank you.

Does anybody know why the blank activity in the latest version of Android Studio now includes two .xml files for each Activity?
For Android Studio 1.5, content_main.xml contains the core UI of the activity. activity_main.xml wraps that in a bunch of other stuff (e.g., CoordinatorLayout) to demonstrate a couple of particular UI elements (e.g., FAB). activity_main uses <include> to incorporate content_main by reference.
These templates change occasionally, and so if you are reading this in the future, your edition of the templates may differ substantially (and please stop reading Stack Overflow answers from your flying car, as that's a safety hazard).
I'm wondering what Android's "bigger picture" is with these changes?
IMHO, you are seriously overstating the role of these templates. They are samples, nothing more.
Is it wiser to develop any future applications using this new Blank Activity format?
It is wiser to not pay all that much attention to the templates. They are samples, nothing more. Developers should know what they want to build and how they want to build it. If one of the templates is close to what is desired, use it. Otherwise, skip the new-activity wizard entirely and just add the new activity yourself.
In cases where the new-activity logic is not directly avoidable (e.g., new-project wizard), either use "Empty Activity" (as it has the least stuff that you would need to delete) or find some other solution. For example, other than for experimenting with the new-project wizard itself, I never use it, and I make a few Android projects a week. Instead, I'll copy an existing project and adjust it to the new package name and stuff, then import it into Android Studio, as I find that less irritating than having to rip out template-generated gunk.

If you choose Blank Activity then you will have the option of having the activity use a Fragment. Also, Android Studio will automatically create two layout files for the activity, three if you choose the Fragment option, and also a menu resource file.
If you choose Empty Activity then you get to choose whether or not you want Android Studio to generate a layout file for the activity. If you choose the layout file option Android Studio will create one layout file, as opposed to two layout files in case of Blank Activity, and no menu resource file. Also, the layout file is much simpler and does not contain things like: Coordinator Layout, Floating Action Button, etc., whereas the layout file for Blank Activity contains these items, assuming you are using the latest version of Android Studio.

Related

Android Studio changing ID's in one xml file changes the ID's in another file

I used to give simple ids to Android Views, but lately, I stopped that altogether because of this issue.
Let's say I have 2 layouts, one named first_layout.xml and second named second_layout.xml. In each of these layouts, there is a view with id username_input. This id is used in different activity classes to access target view, be it ButterKnife binding, Kotlin Android Extensions, or even findViewById.
Now, for whatever reason, I need to rename id in just one layout. Thus I do Refactor -> Rename. What happens? Android Studio simply replaces id username_input in the whole project, messing other layouts that had view the same id. Most people don't use a unique id for each and every view in the project since it's not mandatory, but I do because I do lots of refactoring, and many times I lost hours because of this non-contextual replacement in the project.
What are my options in this case? Is there a way to make Android Studio do the contextual replacement in such a situation, or should I keep making unique ids in my project?
Moments ago I was facing this same issue and I found it to be the Android Studio's expected behavior, as other elements might be constrained to the element whose ID is getting changed. So you need to update all the IDs particularly in your new layout file through its text editor AND NOT from the Attribute section of its design editor
Its working fine for me, and so must work well for you too :)
I too faced same issue, when i copied widget from an one activity to another activity and tried to change ID in copied widget. It prompt a dialog box and i clicked "No (Local Only)". But, i feel no use of that option. it still updated ID in old activity too.
Workaround:
Try to change ID or Attributes through Code(Text Editor) not from Design.
I feel google should address this issue and remove this bug.
Right click on the id you want to rename the go to:
Refactor -> Rename
Now you will see an option "Scope" and under Scope you need to select "Current File" in order to rename the id in that file only.
(Not sure if it was there when this question was asked!)
I just came across this post because I was having a similar problem. I have an app with different flavors. In one of my layouts I have 12 buttons. In a different flavor, I want all of those buttons plus I add 4 more. So, I created a new version of the layout in a flavor-specific directory. The problem is every time I tried to change anything that has an ID it would change the identically-named layout in the main directory.
With flavors, you're supposed to be able to override the main directory's layout with a flavor specific one. This was extremely frustrating!
This MUST be a bug in Android Studio. The frustrating part is that it's still not fixed. I installed Android Studio via the JetBrains toolbox since I use other JetBrains IDEs. Currently I'm on version 3.5.3
My workaround
To get around this bug I created a "test" project. I copied the layout code that I wanted to modify, pasted it in the test project and edited it there. When I was done altering it the way I wanted, I created the alternative layout in the flavor specific directory (using the same name as the main directory's layout that I want to override) of the actual project I was working on. Then I copied the layout from my test project and pasted it into the flavor specific file. By doing this, it didn't alter the layout in the project's main directory.
My thoughts
You shouldn't have to do this. It's certainly not the intuitive way. This is why I can't believe that this is anything but a bug. With that said, I hope I have provided a clear workaround for anyone else who's stuck. If I haven't comment below and I will clarify what I can.

Can't edit anything or drag widgets in Android Studio

I started off with a black activity and whenever I try using Android studio, I get stuck in this screen. I cant drag any widgets, enter any text, or make any changes to the user interface. Is there anything I am missing? I downloaded all the Android Studio bundle and I have all the required SDK tools. I have attached a screenshot of what I am currently stuck with.
A screenshot of what I am seeing:
Recently I encountered the same problem myself. After some research I found that you must now use the "content_activityname.xml" file in order to edit the ui of an activity.
In your case this file is located in the layout folder, right under your activity_main.xml in the picture provided.
According to this thread: What is the role of content_main.xml in android studio 1.4? the main.xml now contains the global look of the ui, and also contains the content.xml file which again contains the components of the ui.
You should think of uninstall and reinstall Android Studio and after that creating a new Project. You also are able to look at some tutorials created by the creators of AS. They can be found at Android Developers.

How to view layout-sequence diagram (activity-sequence diagram or user-interface-sequence diagram) in android studio?

I have an android application in android studio, and this app has about 10 activities (or user interfaces).
I can't find where and how I could view the sequence diagram of the activities (or ui) of my android studio application.
I'm looking a plugin for android-studio or something like that. At one point earlier in my usage of android-studio, I seem to recall being able to pressed a button and get to the the UI-sequence-diagram. I can't find that now.
Could anyone offer any help for viewing the sequence diagram of my user-interfaces of my app?
Unfortunately, there is no "one button" solution that interrogates your code and spits out a diagram any longer. There was once an experimental feature that was later removed from Android Studio.
But starting with Android Studio 3.3, you can create your application using Navigation Component, which gives you the diagram you're after.
You define the Navigation graph, which results in an XML file that has all of your navigation specifics. If you go through the trouble to recode your application to use NavController (and the related components), you not only get the diagram, but this scheme takes care of a lot of up and back actions automatically, and lets you pass data between activities with ease.
Try Tools -> Android -> Navigation Editor

Combining several android applications together

I am working on an android group project in college and this is the first big project many of us have worked on.
We worked on implementing several pieces of the project as completely separate projects and now are having trouble putting all of them in one application with a main page.
On the main page of the application we would have a bunch of buttons that would then go to the implemented project that we've completed (example, I click on BMI calculator on the app homepage and it goes the the bmi calculator screen).
Any efficient way of going about this that can be explained in an easy to follow manner? I'm still a newbie programmer :)
Just to clarify, I don't want it so that it just launches a BMI calculator app from the main app, the entire code base is supposed to exist under one app.
Thanks
You can have a main project and several other projects declared as library projects.
In build time, library projects are pulled into the main project and only one apk will exist as the output.
The library projects are almost the same as an usual android project. You can have java packages, res folder, lib folder, etc.
Check here for the official description.
Check here for a tutorial.
Look into making the other applications as Android Library-projects, and listing all necessary components on your AndroidManifest.xml on your parent project.
Another way would just give the option for the user to install these applications as separate and have a logice (PackageManager) check if specific application exists or is installed and then enabling navigation buttons or disabling components and invoke them via Intents.

XML layout editor

I'm new to android programming, but one thing that I can't seem to get down is writing the XML files. I use a program called droiddraw to help generate the xml code. This program is very simple because it lets me add buttons and DRAG them where I want them. Once I get the screen/form (or whatever it's called) setup the say I like, it will generate the the xml file for me. My question is this: "Does eclipse have a plugin that will do that too?" I know that I can view the form/screen that I can designing, and add buttons and such, but I can't drag them to where I want them. I always have to edit the layout values manually.
The xml layout editor that ships with Eclipse is pretty woeful. Thankfully Google are putting effort into improving this so that we have a more seamless drag n drop experience. You can download and compile the latest works here http://tornorbye.blogspot.com/2010/11/building-android-ide-tools.html
or just wait a week (or two) for Gingerbread to be released. A stable version is sure to be included in the Eclipse ADT update that is released then.
ADT is nicely integrated into Eclipse for Android development.

Categories

Resources