How to Handle Multiple Application Classes in Android

how to handle multiple application classes in android

You need to implement Multilevel inheritance to resolve this scenario.

This is your scenario

public Lib1Application extends Application{

}

public Lib2Application extends Application{

}

public YourApplication extends Application{

}

How to resolve this?

public Lib1Application extends Application{

}

public Lib2Application extends Lib1Application{

}

public YourApplication extends Lib2Application{

}

finally in mainfest.xml

<application
android:name="com.your.packagename.YourApplication"
android:icon="@drawable/ijoomer_luncher_icon"
android:label="@string/app_name"
>

How to Use Multiple Application class in android?

It's not impossible, your ApplicationLoader must extend AbtoApplication in this case.

Multiple Application Classes in one Project

no need of that, Android your application can handle only 1 application class else you want multiple for that you have to extend B_Application class from A_Application class.

how to have multiple application classes in separated jars in one application in android

The solution is you should extends one of your app classes from upper classes (that extended itself from application class or from some app class that extended itself from application class (these are in chain).

In question, you should make a appp class that extended from soomla, and then extend soomla from push, and then push from Application class and then set push class in manifest.

public appp extends Soomla{

}

public soomla extends Push{

}

public push extends Application{

}

In mainfest.xml :

<application
android:name=".push"
android:icon="@drawable/ijoomer_luncher_icon"
android:label="@string/app_name">

How do you handle multiple application classes in a xamarin android project

So I was able to figure out a solution but it boarders on being a hack.

In short the android manifest is going to be modified using MSBuild.

Step 1: Have your custom application class inherit from the the Third Party lib's custom application and decorate your class with the "Register" tag.

[Register("com.namespace.MyApplication")]
public class MyApplication : ThirdPartyApplication
{
}

Step 2: Have your project include the RoslynCodeTaskFactory NuGet package

Step 3: Unload your project, then add the following in the Project tag

<UsingTask TaskName="UpdateManifest" TaskFactory="CodeTaskFactory" AssemblyFile="$(RoslynCodeTaskFactory)" Condition=" '$(RoslynCodeTaskFactory)' != '' ">
<ParameterGroup>
<AndroidManifestFilename ParameterType="System.String" Required="true" />
<ApplicationName ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.Xml" />
<Code Type="Fragment" Language="cs"><![CDATA[
XmlDocument doc = new XmlDocument();
doc.Load(AndroidManifestFilename);
XmlNode node = doc.DocumentElement.SelectSingleNode("/manifest/application");
node.Attributes["android:name"].InnerText = ApplicationName;
doc.Save(AndroidManifestFilename);
]]></Code>
</Task>
</UsingTask>
<Target Name="CleanManifest" AfterTargets="_GenerateJavaStubs">
<UpdateManifest AndroidManifestFilename="$(ProjectDir)\obj\$(Configuration)\android\AndroidManifest.xml" ApplicationName="com.namespace.MyApplication" />
</Target>

Step 4: Reload the project and build. The manifest should now point to custom application class. If you get a class not found runtime exception most likely you forgot to add [Register] from Step 1.

Android multiple application in one androidmanifest

According to the documentation, only one application tag can be inserted in the manifest.

Quote from doc:

"Only the manifest and application elements are required, they each must be present and can occur only once."

If you're following the example at the given link, just add the android:name and android:label XML element to your current application tag and it'll work just fine.

Example of my application tag in an application I'm developing at the moment:

<application
android:name=".Globals"
android:debuggable="true"
android:icon="@drawable/icon"
android:label="@string/app_name" >

Globals is my application class.

Multiple Application name in Android Manifest

I'm guessing you are using a Singleton as to have a class that holds your App data for the current session and\or another one for specific stuff (e.g. networking), if so, you have a couple ways of going about that:

  1. Use ONE Application class - you shouldn't have more than one, if so - merge them.

  2. If you insist on having 2 Singleton classes because you want to separate some functionality, you may create 2 Singleton classes, which are NOT your application class.

If you choose option 2, you should initialize(and maybe also control) them from your application class, especially to avoid duplicating a context object (that might lead to a memory leak), but make sure it's really necessary first.

since you tagged your question with the Volley tag, I'm guessing this SO thread about isolating Volley requests might help.

Hope anything here helped!



Related Topics



Leave a reply



Submit