I have been working on a bunch of utility activities. The goal is that the user simply can reuse the source code and there is no need for any layout xml files. Hence, all the layouts are created programmatically. There is no reference to any layout xml file.
The only problem I am running into is that the user is forced to enter the activities in the manifest file.
I am wondering if there is a way to bypass this step by the user. Perhaps the user can call some Init() method in my code that will programmatically add activities to the "manifest" object. There must be some notion of manifest object as Android is looking it up when a new activity is created.
Thank you in advance for your help.
The goal is that the user simply can reuse the source code and there is no need for any layout xml files. Hence, all the layouts are created programmatically. There is no reference to any layout xml file.
This hardly seems like a good thing. Now you are preventing your reusers from readily modifying matters, to tweak for different device characteristics that you are not yet supporting, etc. Android library projects allow you to create reusable components that contain layout files and other resources.
I am wondering if there is a way to bypass this step by the user.
No, sorry, that is impossible.
Eventually, I think Android library projects will support merging of manifests to help deal with this.
Related
I am working on application with multiple types choices and every type has different UI, content and operations.
If i packaged all activities, xml and drawables files inside same .apk file for all users with showing and hiding methodology it's an inefficient way as it waste user space and download time.
Are there another ways to upload activities,xml and drawables files to external servers and download them based on user selected choice?
appreciated any help.
thanks.
You may download the Activities and other Java classes from the server and load them up, perhaps even Drawables, but XML part would be a tricky one.
If you can manage to avoid XMLs by creating layouts with Java if Layout is what you meant by XML, the answer is yes, it is possible.
You will need to explore how to load Java classes at runtime.
the answer is here
Multiple APK Support
-----> The build system enables you to automatically build different APKs
that each contain only the code and resources needed for a specific
screen density or Application Binary Interface (ABI). For more
information see Build Multiple APKs.
folks. I'm beginning Android development and all of the tutoring videos constantly mention XML file. I looked up the meaning of XML which says:"XML was designed to describe data." But WHY is XML needed in Android and in general(please explain in simple understandable words)? Is there any way to create projects w/o XML file? Thanks in advance!
According to Android documentation:
The advantage to declaring your UI in XML is that it enables you to better separate the presentation of your application from the code that controls its behavior. Your UI descriptions are external to your application code, which means that you can modify or adapt it without having to modify your source code and recompile. For example, you can create XML layouts for different screen orientations, different device screen sizes, and different languages. Additionally, declaring the layout in XML makes it easier to visualize the structure of your UI, so it's easier to debug problems.
Using Android's XML vocabulary, you can quickly design UI layouts and the screen elements they contain, in the same way you create web pages in HTML — with a series of nested elements.
Short answer. To make your life easier.
I'm having a lot of doubts and after two days of searching I still haven't found a good answer for my problem.
I have an app's project that is already in the store and this project have lots of Activities, Fragments, Services, IntentServices, Layouts, and resources (images, strings, integers, colors, styles, raws, drawables, etc...).
Now, I need to implement a new app that is almost a copy of the first one where I need only to change the background, some resources (but almost 99% stay the same), and maybe in one or two fragments I'll need to change some code (implement different logic statements).
I decided and I think it's natural to convert the all project in an library project.
I did:
1º Create a new project called framework and configured as library. Copied all code and resources (with the exception of assets folder) from the original project to here.
2º In the original project I leave only the manifest, proguard file. I change the manifest and proguard file to reference the classes of the new library.
I tested the app to see if was still working and it was Ok. Until now I did only the separation.
Now, came the problem. I need to create a solution reusable,and scalar for the library that allows me to use it in different apps.
In my original project I created a subclass of Application class that I use for global variables.
Without any others ideas, I decided the following:
1º Convert my MyApplication class in an abstract class. Also, I create an interface ApplicationInterface with some methods like isBackgroundOverlayed() or getBackgroundResource() that I use in the fragments to change the backgrounds or any other logic from the originally defined.
2º In the App's project, I created a new Application class that extends the abstract class MyApplication and implements the interface ApplicationInterface and which is declared in the Application tag in the manifest file.
Conclusion: This all works and I was able to have two app's projects with different background and other images like logos and even change some code logic. An example is in the original App when the user press one certain button, the App shows a dialog choice. In the new app when the user press the button it execute one fragment (without choice).
My concerns: I don't feel this is the best solution for the problem or best practice or good "pattern".
Do you have any ideas?
Thank you in advance!
ps: Sorry if I haven't use this forum properly. I search for an answer but I didn't found any.
I think you have achieved what you wanted, but that was a lengthy and time consuming process. One more thing I would like to mention is you should not change library projects for different applications
As said on Android developers guide :
Library projects contain shareable Android source code and resources that you can reference in Android projects. This is useful when you have common code that you want to reuse.
you can read more from here
Also you have to figure out,which lib is doing which work in case you forget what changes you have made
I would suggest you to keep a separate copy of original project and then import it into new work space in Eclipse (by checking copy project into current work space so that you have a new copy of your project) and consider changing its package name to get a new project
you can refer ans on this link to see how to change package name`
I am trying to write a modular extensible application to deploy in Android. The idea is to provide an API to allow the creation of custom functionality for the app that may include custom layouts and other resources. This custom functionality will be loaded, at runtime, from another location (e.g. SD Card).
Currently I am able to load .jar files from this location and work with them as I like, unfortunately I can only include references to layouts and resources that are also present in the "Main" project.
I have been unable to find a good way to reference an entire library project, resources included. I essentially want each custom piece to contain all the resources it needs to display and run itself.
Right now I am toying with the idea of including an "Assets" project that can be referenced by each of the modules to be a central area to store layouts and other resources. Unfortunately this would require me to have a project that must be loaded by any other project that needs to be built.
Another idea was to include the layouts, images and strings, along with the jar files, in a folder and load those at run time. I don't think this will work well since the layouts seem to be pre-processed at compile time in some way and cannot be inflated at run time.
Does anyone know a way for me to include all the resources and code into a single, dynamically loadable, file that I can then access at runtime?
Does anyone know a way for me to include all the resources and code into a single, dynamically loadable, file that I can then access at runtime?
That is not supported. It is rather likely that it will never be supported, though it is possible that it might work with the new build system that is under development.
the res/layout* dir of my projects are getting really messy lately and as there are afaik no subdirs allowed there to change that. So it is hard to get structure in there - how do you guys do that?
I don't know about others but for myself I like to use prefixes to help keep things sorted, essentially taking the place of subdirectories. For example, all my activity layouts start with 'activity_' and all my UI controls start with 'control_', notifications with 'notification_', etc.
I am then left with a flat directory with at least some structure, something like:
activity_graph.xml
activity_main.xml
activity_map.xml
control_graph.xml
control_title_bar.xml
notification_just_label.xml
notification_with_progress_bar.xml
...
It's not perfect, but it works for me.
Sorry subfolder inside the layout folder is not possible other than docs specification.
Just check this and this and this question.
Another possibility is to refactor some elements of your application into libraries.
For example you could extract unrelated fragments (as fragments should per se be unrelated) into libraries, mark that project as an Android library (check "Is library" in project properties) and then use your own libraries in your main project.
The resources you need within the separate libs will not collide anymore, but will be "thrown together" at build time, so access is fine.
Here are the docs for that.