How to launch combined app without seperation - android

I've combined two apks. One of them runs only on background. So I thought that It must have been easy to do. But I have a problem. After I install my signed apk I see two of them on the menu. Why are they seperated? How can I make them run together? Here is the activity part which causes the problem.
<activity android:label="#string/app_name" android:name=".MainActivity" android:theme="#android:style/Theme.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:configChanges="orientation" android:label="#string/app_name" android:name=".FreeMemoryRecover">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

You're defining both of them as launcher activities, which is a perfectly legitimate thing to do, just not what you want. Define only one as a launcher activity, and have it launch the other in a new task.
Note that you cannot launch an activity into the background, only launch an activity over the current one. And there is no guarantee that an activity will continue to exist once it's in the background or even in the backstack of the same task. It sounds like you should convert one of your activities to a Service.

Related

singleTask activity not loading properly

I have an activity 'A' defined in Manifest like below:
<activity
android:name=".A"
android:launchMode="singleTask"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
When I launch my APP, that activity is always loaded from the start. It wont start from my prev activity.
When I remove android:launchMode, then it works as I expect.
Since you set android:launchMode="singleTask", the activity A will always be the root of your activities.
From DOCS:
In contrast, "singleTask" and "singleInstance" activities can only begin a task. They are always at the root of the activity stack. Moreover, the device can hold only one instance of the activity at a time — only one such task.
Default mode is standard. So, when you remove android:launchMode="singleTask", your APP returns to standard launch mode.
That's why if you app is always starting Activity A.
If you would like to start a different Activity on launch replace that in the xml name attribute that contains LAUNCHER
<activity
android:name=".ActivityB"
android:launchMode="singleTask"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Where Activity B is an alternate activity.

When using taskAffinity to have multiple Activities in the Launcher for the same app, if one is active the other needs to be clicked twice

Scenario:
Two Activities being shown in launcher for one app, they have different taskAffinities because I was getting the problem of when I open one, hit home, open the other, the first one would be opened. So, I added taskAffinity in the AndroidManifest for the proper tasks.
The problem I'm getting is that if I open one, hit home, hit the second one, it will open the proper task/Activity, BUT I have to click on the icon twice in order for it to open and get, this ONLY happens with the activity that specifies a taskAffinity, the other one opens just fine on the first click every time.
731-1337/? W/InputMethodManagerService﹕ Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#4e640b6 attribute=null, token = android.os.BinderProxy#3edac0ca
Here is the manifest
<activity
android:name=".firstActivity"
android:theme="#android:style/Theme.Holo.Light.NoActionBar">
<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="#string/second_activity"
android:icon="#drawable/ic_second_activity"
android:taskAffinity="secondTask"
android:theme="#android:style/Theme.Holo.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".thirdActivity"
android:label="#string/second_activity"
android:taskAffinity="secondTask"
android:theme="#android:style/Theme.Holo.Light.NoActionBar"/>
I fixed this by adding this to the thirdActivty which was being called by secondActivity immediately on launch.
android:launchMode="singleTask"
So it ended up looking like
<activity android:name=".thirdActivity"
android:label="#string/second_activity"
android:taskAffinity="secondTask"
android:launchMode="singleTask"
android:theme="#android:style/Theme.Holo.Light.NoActionBar"/>
Hope someone finds this solution helpful.

Application icon for each activity

I have used web view in two of my layouts in the application and when I install the application in my phone I could see separate icons for the activities whose layouts have web view. How will i fix this issue and why does this happen so? Please advice.
Probably the reason is that you have several activities in manifest that have the MAIN, launcher intent. To fix it, remove it from one of them.
<activity
android:name="com.example.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>
to
<activity
android:name="com.example.MainActivity"
android:label="#string/app_name">
</activity>

Android application with two application buttons

I am new to Android development. Currently, I am creating an Android app which should have two launching icons.
First icon to launch configuration part of the app.
Second icon which will execute based on the configuration.
Configuration will be not be frequent activity.
But launching of second icon will be very frequent to get the results based on configuration.
As I can see most of the apps have single launch icon.
Is there a way in Android which can fit into my requirement?
Thanks.
This might work.
In your manifest file (AndroidManifest.xml):
<application android:hardwareAccelerated="true" android:label="#string/app_name"android:icon="#drawable/ic_launcher">
<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="SettingsActivity"
android:label="#string/app_name">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

How do I get multiple icons to launch different activities in one application?

I have an application with two activities and I'd like to be able to have two icons appear in the launcher, each launching the respective activity within the app.
Specifically, I want one icon to launch my main app, and another icon to launch my settings activity. Is this possible?
Here is what I've tried so far:
<activity android:label="MyApp" android:name=".MyApp">
<intent-filter>
<action android:name=".MyApp"/>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:label="Settings" android:name=".Settings">
<intent-filter>
<action android:name=".Settings"/>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
This creates two launcher icons, but they both run my main app instead of the second icon running my settings app. I've tried just having the launcher category but then I don't get an icon so it looks like I need the main action as well.
Is this the right approach or should I be declaring two applications in the manifest instead?
What you need to do is have your settings activity launch in another task. You can do this by specifying its task affinity. This is done with the attribute android:taskAffinity. By default all activities share the same task affinity that defaults to main package specified in the manifest. On your settings activity you can specify android:taskAffinity="your.own.package.SettingsTask" to have the settings activity launch in its own task.
Extra documentation.
You're definitely going in the right direction. This is what I have (truncated, because I have all of my activities in the list while I'm devving for fast access):
<activity android:name=".DeckDrill"
android:label="DeckDrill">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DeckList"
android:label="DeckList">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I think what may be happening is interference from your action elements which specify the name of your class. I'm pretty sure that actions and categories need to refer to constants. I don't know how that would result in what you're seeing, but you could try removing them. Other than that, you pretty much have what I have.

Categories

Resources