I've followed the Android documentation to create a library. Basically, I've created a new project and, then, edited it's properties to check the "is Library" box. Then I've added a reference to it at my runnable project, using also "project properties"->android->Reference.
Everything seems ok, but I can't figure out how to, from the runnable project, start an activity I've put in the library project. For example, I start an activity that is inside the project using
intent = Intent(this, ActivityClassName.class);
But the following, which I tought was the correct for a activity in a lib, doesn't work
intent = Intent(com.example.libpack, ActivityClassName.class)
I've put the exported activities in both manifests (lib and runnable)
I've seen some hints on web, but things are very obscure to me. This is the right way to export and embed an lib? Or should I use the Export option in Eclipse File menu to export a JAR file from the library? If both are possible, which would be better?
You're doing right, but the first argument to newIntent() is not the package the activity is in, it's just the context. It will probably work if you use again this. If it still doesn't work, please edit your question to include the error you're getting (check LogCat and Console tabs).
When a context is required and you're in an Activity, it's better to use getApplicationContext() instead of this (see here).
Related
still learning android and this is where i am stuck.
I want to use this project as a tutorial for my app
https://github.com/PaoloRotolo/AppIntro
It has a wiki, and it says i need to add gradle dependency which i'm pretty sure i'll handle properly.
Whats bothering me is how do i extend that app to my class? where do i put that project/library inside my project?
Sorry if this question is newb-ish, i tried alot of things and they didn't work.
Thank you for your help!
Since you said you'd handle adding the gradle dependence I believe you are asking how to implement an Intro screen? Did you read the How to use part on the home page of the library?
Everything is explained there. What to extend and what each method does. For the actual creation of each fragment I will give you a hint.
After creating a new class for your Intro screen, if you don't have a specific layout for your fragment just use that part of the code:
addSlide(AppIntroFragment.newInstance(title, description, image, background_colour));
where the parameters are variables that you choose. For image you could use any of your images inside the drawable folder like R.drawable.intro_ico and for background colour - ContextCompat.getColor(this, R.color.grey)
'grey' color has to be created in your colors.xml or choose anything you like.
EDIT: And if you were wondering whether you should download something and where, no you are all done only by adding these lines of code to your build.gradle. When you add them, Android Studio asks to Sync the gradle file, and then it downloads the library.
For some libraries, you'd need to download a jar file or git clone from a repository and then maybe add the downloaded folder as a Module to your project by going Android Studio>New>Import Module>locate the folder . However, for that one, adding the dependency is enough as it gets downloaded after the Sync.
it's really very simple!
you just add these lines :
repositories {
mavenCentral()
}
dependencies {
compile 'com.github.paolorotolo:appintro:3.4.0'
}
in your build.gradle file under app folder.
I'm trying to create my first app with Android but I've encountered some problems.
Following a tutorial and making:
new android application -> blank activity
The default result should be:
With MainActivity.java and R.Java inside it.
But instead I've got this:
There are a lot of errors and the R.Java file is missing.
I can obtain a result similar to the tutorial one (with no errors), creating a new android application and unchecking create activity, but this time MainActivity.java under src is totally missing.
Maybe I could copy the MainActivity.java of the first project and put into the second one, but I prefer understand why it doesn't work.
Thanks for the help.
Best regards.
its import library problem
Right click on you application----->Android
under library view ,
check if you have this red error then remove the library and add it again
I'm trying to learn how to program android applications, so I downloaded the ADT bundle that google supplied, and I tried following the tutorial that allowed me to create a simple application. However, during the procedures, there are several instructions telling me to open up the fragment_main.xml file, but my layout/res/ directory did not have this file, only the activity_main.xml file. Furthermore, when creating new Android activities, there was never an option to name my fragment layout, indicating that eclipse just doesn't create it for some reason. I didn't think this would be an issue at first (I just edited activity_main instead), until I realized that the tutorial wanted us to use the some information from the fragment class or xml file.
Does anyone know why my Eclipse IDE is not creating a fragment_main.xml? I will try to supply more details if necessary.
While creating the new Android Project in one of the panels select "Blank activity with Fragment" instead of default selection "Blank Activity". The Android Developer tutorial does not say anything about it. Doing so will create the file fragment_main.xml in res/layout/ which is needed to continue subsequent steps.
Based on the versions you indicated in the comment response, I think updating to the later versions (22.6+) would help, as discussed in https://code.google.com/p/android/issues/detail?id=67421
Try creating a new project with "Blank Activity with Fragment". I hope this is helpful.
Open MainActivity.java from the src/(package name file)/ directory. Then inside the java file there is a method called OnCreate() that has setContentView(R.layout.activity_main) as default.
Change that to R.layout.activity_main to R.layout.fragment_main
so instead of having
setContentView(R.layout.activity_main)
you'll have
setContentView(R.layout.fragment.main)
Once that's done change the name of the activity_main.xml file under the /res/layout/ directory to fragment_main.xml
Thanks for that Onik!
This is probably realy noobish question but, i am unable to solve it. I dont know what i am doing wrong or what should i do, i checked some tuts but i wasnt able to solve it. So i created new folder in res called menu and created new file there called xyz.xml. Now i want to call it in activity with following R.menu.item ... But when i just write R. it doesnt show menu as option. I can call any map which are default here like layout etc, but maps which i created i cant call them. What should i do to solve this?
If the menu file you create is called xyz.xml, then in your code you should use it as:
R.menu.xyz
Also, are you referring to the correct R? There's one R class used for the Android framework resources (android.R) and then there's one specific R class for your projects resources. To ensure you're using the right one you can use the fully qualified namespace, e.g. yourprojectsnamespace.R.
See http://developer.android.com/guide/topics/ui/menus.html for more information about Android menus.
Quite new to Android dev so there is a good chance I made a dumb mistake. But for some reason I cant reference a ImageView I created in a second Activity using the findViewById method. When I went and checked the 'R' file I could see that an Id was not created for all 3 ImageViews I am trying to reference that is in the same activity.
What could the possible reason be for this? Could it be something to do with data I put in the Manifest file? My java class? Because my syntax for the containing activity is 100%....
I'm suspecting is has something to do with the new activity/manifest. How can all the ImageViews in the same Activity not be referenced...?
Clean the project and try again. To clean you project Project -> Clean select your project and clean. Some time it happens while developing the project. I've faced many times.