How do I load an Activity from within a Library? - android

I've got a projected marked as "Is Library" - it has all the activities. I've got a new Android project that references this library. How do I mark one of my library's activities as the first one that starts up?
EDIT
My original manifest looks like this:
<activity android:name=".Welcome" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
All my activities are in the package com.rjs.animator.

As long as you AndroidManifest.xml contain those Activity tag and reference to the correct namespace/class within your Library, you should be good to go.

You have to add all activities and other components to the new Android project's manifest, with whatever <intent-filter> elements you want. Just put the standard MAIN/LAUNCHER <intent-filter> on whichever activity you want.

Related

Android install each layout like application

I make android application with two layouts, when I export project, and install it on phone and tablet I got two icons in menu, first open main layout, when I start second icon it open second layout
Is problem in layout calling, I make two classes for layout.
How I can solve this? thanx
You just need to call new activity ..
Intent intent = new Intent(YourCurrentActivity.this, NewActivityToOpen.class);
startActivity(intent);
Also don't forgot to define same over AndroidManifest.xml .. :)
<application ...>
<activity android:name=".YourCurrentActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".NewActivityToOpen" />
You may need to put the fully qualified java classname to android:name.
Problem in manifest file.
When you declare activity u sign all activity with
<intent-filter>
<action android:name="android.intent.action.MAIN"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="landscape"
/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
But this code using only for first activity^ next must declare only like:
<activity
android:name=".YourClass"
android:label="#string/app_name"
>
</activity>

Android Eclispe : 2 .java files in editor, how to set1 file as startup

In nutshell, i am trying to add multiple examples, by adding multiple .java files, in editor but all the time, mainactivity.java file is being executed. How could i make other file as start up file.
If your other file is also an Activity, which it must, you will have to change your AndroidManifest.xml. Add a new entry for your new Activity, and add the Main and Launcher Intent filter:
<activity
android:name="com.example.activity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Also make sure to either remove the Intent Filter from the Manifest entry of the old Activity.
Yep you are gonna use the AndroidManifest.xml file, you can actually even have more than one launcher activity specified in your application manifest. To make an activity seen on the launcher you add these attributes to your activity in the manifest
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Change this*.Launcher* to Default for your MainActivity and Add .LAuncher in that activity you want to Launch First

How to change the startup activity in android?

I have two activities namely login and calendar in my Application. Currently my startup activity is "calendar". I want to run the login as first activity not calendar.
The startup activity [Launcher Activity] is declared in the projects' AndroidManifest.xml file
Look for that activity tag in the manifest which looks like this
<activity android:name=".Main"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Look at the attribute android:name. Main is the class which is launched when the app starts. Currently your calendar activity name should be there. Change that to the .classpath of your activity that you want to launch.
That should do it. You may also want to do the hello world application in the tutorials and go through the docs a little to see how Android Applications work.
Add Intent filter to the Activity in which you want startup.
In your case Modify the AndroidManifest.xml file as follows
<activity android:name=".login"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
remove the intent-filter code from calendar Activity tag in manifest and add it to the Activity you wanna load first
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
I mean paste it in the activity you like to run as default.
<activity
android:name="com.example.gridviewimages.AnotherActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Where as
From the docs
category -- Gives additional information about the action to execute. For example,
CATEGORY_LAUNCHER means it should appear in the Launcher as a top-level application, while
CATEGORY_ALTERNATIVE means it should be included in a list of alternative actions the user can
perform on a piece of data.
MAIN means that this activity is the entry point of the application, i.e. when you launch the application, this activity is created.
You want the Application element of the Android Manifest file. You can see details here.
Look at the name attribute, this points to the Application class.

In android every .java file becomes an app on the phone!

I have 6 .java files under one package.In eclipse, after I export the .apk and install the app on the phone or if i run the app on the emulator, there are 6 applications created, one for each .java file! The java files are different screens in my app.So i can open any java file by clicking on the icon in the menu.I only want one of them to be openable through the icon in the menu. So basically, only one icon should be seen in the main menu, which upon clicking opens the first activity in the manifest file!
Any idea whats wrong?
Thanks.
My assumption:
You registered all your Activities in the AndroidManifest (which is right) but as intent-filter you always used
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
That intent-filter tells Android to add the Activity to the launcher. Remove those Intent-filters (except one Activity that's going to be your main entry point) and it should work.
What does your manifest say? It might specify that all activities are shown as seperate apps...
Just check your AndroidManifest.xml file and modify your activity same as below code example:
<activity android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity"
android:label="SecondActivity">
</activity>
So if you mark the above code then you can easily come to know that the below code mention that this activity is going to be act as a launcher activity.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Try to mention the intent-filter action as MAIN and Category as Launcher only for your entry activity in your app.
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>.
Remove this for all other activities except the entry point for your app.
Hope this helps.

Multiple program shortcuts from one application

In my application I have a number of Activity classes. When I run on emulator (or install to a device) a corresponding number of program shortcuts show up in the programs menu. Why does this happen and how can I avoid it?
Many thanks.
I think you have added LAUNCHER attribute in every activity...so multiple shortcuts showing up in your program menu.
But,
There should(mostly) only one "LAUNCHER" activity....
Do like Following:
<activity android:name=".Testing"
android:label="Showing Testing">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity1"
android:label="#string/Activity1">
</activity>
<activity android:name=".Activity2"
android:label="#string/Activity2">
</activity>
<activity android:name=".Activity3"
android:label="#string/Activity3">
</activity>
</application>
I think you need to look in your manifest file. I believe that is where the intents are defined.

Categories

Resources