How to change activity hierarchy? - android

I build a project with many activities. Every time, when I was creating new activity, I set a hierarchy parent. But I decided to make an activity with animation, which should be first. I tried to change some information inside manifest file and set the new one activity as the starting activity, but I'm doing something wrong and all the project is crushing. Ofc, I will be keep going and trying to change the manifest file, but maybe I can do that in an easier way using Eclipse tools?
--EDIT--
I solved my problem, it was a quite small mistake. I was just setting wrong layout and forget to change one more thing. I'm not a specialist yet on this topic, but maybe for other readers I will put here some information how to change the hierarchy using manifest file. If I will make any mistakes here, feel free to edit.
Ok, so let's suppose we have our project with a few activities. Inside Manifest file we can find some information about activities, this informations are between markers: . So, it may looks like:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.mastermind.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="com.example.mastermind.StartGameActivity"
android:label="#string/title_activity_start_game"
android:parentActivityName="com.example.mastermind.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.mastermind.MainActivity" />
</activity>
<activity
android:name="com.example.mastermind.NewActivity"
android:label="#string/title_new_activity" >
</activity>
Now we want to change the MainActivity, which is the first one and set as the first one the NewActivity. We only need to change the name of activity which contains markers:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
for the name of NewActivity and also set it's layout, like this:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.mastermind.NewActivity"
android:label="#string/title_new_activity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.mastermind.StartGameActivity"
android:label="#string/title_activity_start_game"
android:parentActivityName="com.example.mastermind.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.mastermind.MainActivity" />
</activity>
<activity
android:name="com.example.mastermind.MainActivity"
android:label="#string/app_name" >
</activity>
That should be Ok.

In the manifest file locate category.LAUNCHER:
<activity
android:name="com.example.StartActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /><!-- This -->
</intent-filter>
</activity>
<activity
android:name="com.example.MainActivity"
android:label="#string/app_name" >
</activity>
The category.LAUNCHER declares your launch Activity.

Related

When running application A from the launcher it sometimes also runs application B

I have one Gallery application (A) that binds to a service.
I have second transparent application (B) that just runs a service unbound and closes itself.
sometimes - when running application B from the launcher it also runs for a split of a second the application A. I see the layout of application A appears and disappear.
I suspect that something in the manifest is defined wrong : launchMode or taskaffinty.
any ideas?
<application
android:allowBackup="true"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name="com.temp.tempApp.GalleryActivity"
android:theme="#style/AppTheme.NoActionBar"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:label="#string/app_label_gallery"
android:excludeFromRecents="true"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.temp.tempApp.MainActivity"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:launchMode="singleTask"
android:label="#string/app_label"
android:theme="#style/Theme.Transparent"
android:windowSoftInputMode="stateHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.temp.tempApp.MainService" android:enabled="true"
android:exported="false">
</service>
Found the answer, one of the following fixed it:
1. add to each activity specific afinity value "android:taskAffinity="com.example.MainActivity""
2. different icons for the 2 activities.
hope it helps somebody in the future

Ad overlay requires the useClientJar flag in intent extras.

Ran into this issue trying to get Interstitial Ads to work on my first android app. Being a complete novice I really had on idea how to add the "useClientJar" flag to the Intent Extras.
This wasn't the issue, it's actually an error in the AndroidManifest.xml and I'm posting this question/answer because it's one of the few situations I've run into with only 5 relevant google results, the top one being a piece of IRC chat with one poor guy running into the same problem as me.
The issue is that I had foolishly made my main activity into the AdActivity in the AndroidManifest.xml like this:
<activity
android:name="com.google.android.gms.ads.AdActivity" <!-- notice this name, this means the interstitial ad is now the main activity! -->
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The fix of course was to correct this like so:
<!-- They are now two separate activities -->
<activity
android:name=".FullscreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Translucent" />

Application starting with different activity, Android Studio

first timer here (both in development and posting in SO). I've used idunnololz to create an animated listview for a simple reference app I'm trying to make. It's turned out really well, but after I've created it, when I run the app to test it, it now runs as AnimatedExpandableListView both in the ActionBar title and in the app drawer. I've searched here and found that you can get the app to launch with a different activity by editing the AndroidManifest.xml, so I verified that I'm pointing to my MainActivity class:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<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>
</application>
I presume this may be an issue with the MainActivity class, but maybe there's something here that I'm missing?
I found my answer here:
Android: App name shows the first page name, not the app name
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter **NEED #string/app_name HERE**>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

The <activity> element must be a direct child of the <application> element error

I have added my third class to my package, and I want to add it to my androidmanifest.xml file. I have added the second class easily with no problem, but I'm stuck with the third one.
When do I try to add the third activity:
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.metoo.codedetective.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="com.metoo.codedetective.Etelaateomoomi">
<activity android:name=".Factoryreset">
</activity>
</activity>
</application>
</manifest>
I get The element must be a direct child of the element.
What should I do?
Please correct the code and post it.
thanks for advance
In
<activity android:name="com.metoo.codedetective.Etelaateomoomi">
<activity android:name=".Factoryreset">
</activity>
</activity>
remove <activity android:name=".Factoryreset"> </activity> because this is an activity in an activity which is not allowed.
I think you need this:
<activity android:name="com.metoo.codedetective.Etelaateomoomi.Factoryreset">
</activity>
Remove the following lines that represent an activity inside another activity.
<activity android:name=".Factoryreset">
</activity>

Having a single application name, and not separate activity names

I have an android application with three activities: Loading, Main, Credits.
But when I try to run and look into the emulator, I have three icons: Loading, Main, Credits.
How can I just have a single Application name? And where do I set it?
Set in android manifest file in application level.
android:label="#string/app_name"
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".Loading"
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=".Main" />
<activity android:name=".Credits" />
In your AndroidManifest.xml, you just need to set <intent-filter> for only one Activity other Activities don't need this tag.

Categories

Resources