简体   繁体   English

如何在 Android Manifest 中声明两个不同的应用程序或将它们合并为一个应用程序类

[英]How to declare two different application in Android Manifest or merge them into one application class

I have merged two packages into one: this and this into one.我已将两个包合二为一: 这个这个合二为一。 The problem that I'm facing is that I can only declare one Application in android manifest.我面临的问题是我只能在 android manifest 中声明一个应用程序。 I have two applications to declare: AppController for Volley and ParseApplication for Parse package.我有两个应用程序要声明:用于 Volley 的 AppController 和用于 Parse 包的 ParseApplication。

What should I do to declare only one application in Android Manifest?如何在 Android Manifest 中只声明一个应用程序? I'm still a newbie and trying to learn by merging some code that I find online for practice what I read or watch online.我仍然是一个新手,并试图通过合并我在网上找到的一些代码来学习我在网上阅读或观看的内容。

Thank you !谢谢 !

Update: Here is the Appcontroller class:更新:这是 Appcontroller 类:

Public class AppController extends Application {

public static final String TAG = AppController.class.getSimpleName();

private RequestQueue mRequestQueue;
private ImageLoader mImageLoader;
LruBitmapCache mLruBitmapCache;

private static AppController mInstance;

@Override
public void onCreate() {
    super.onCreate();
    mInstance = this;
}

public static synchronized AppController getInstance() {
    return mInstance;
}

public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        mRequestQueue = Volley.newRequestQueue(getApplicationContext());
    }

    return mRequestQueue;
}

public ImageLoader getImageLoader() {
    getRequestQueue();
    if (mImageLoader == null) {
        getLruBitmapCache();
        mImageLoader = new ImageLoader(this.mRequestQueue, mLruBitmapCache);
    }

    return this.mImageLoader;
}

public LruBitmapCache getLruBitmapCache() {
    if (mLruBitmapCache == null)
        mLruBitmapCache = new LruBitmapCache();
    return this.mLruBitmapCache;
}

public <T> void addToRequestQueue(Request<T> req, String tag) {
    req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
    getRequestQueue().add(req);
}

public <T> void addToRequestQueue(Request<T> req) {
    req.setTag(TAG);
    getRequestQueue().add(req);
}

public void cancelPendingRequests(Object tag) {
    if (mRequestQueue != null) {
        mRequestQueue.cancelAll(tag);
    }
}

} }

public class ParseApplication extends Application {

@Override
public void onCreate() {
    super.onCreate();
    Parse.enableLocalDatastore(this);
    // Add your initialization code here
  Parse.initialize(this, "ui3OHYCLF4wlTNZcbkPhRkiEN4yiURuRZxYnXMSX", "J60b54ajmUuDk7wu94GmX3DpBbJOrv5IzSuRd5V2");

    ParseUser.enableAutomaticUser();
    ParseACL defaultACL = new ParseACL();

    // If you would like all objects to be private by default, remove this
    // line.
    defaultACL.setPublicReadAccess(true);

    ParseACL.setDefaultACL(defaultACL, true);
}

} }

Manifest:显现:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="info.androidhive.listviewfeed"
    android:versionCode="1"
    android:versionName="1.0">

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="19" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <!--
          IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
          to match your app's package name + ".permission.C2D_MESSAGE".
        -->

    <permission
        android:name="info.androidhive.listviewfeed.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="info.androidhive.listviewfeed.permission.C2D_MESSAGE" />

    <application
        android:name="info.androidhive.listviewfeed.ParseApplication"

        android:allowBackup="true"
        android:label="@string/app_name">
        <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=".Feed_Activity"></activity>
        <activity android:name=".Login"></activity>

        <activity android:name=".Welcome"></activity>

    </application>


</manifest>

` Debug ` 调试

10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: FATAL EXCEPTION: main 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: Process: info.androidhive.listviewfeed, PID: 1688 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.listviewfeed/info.androidhive.listviewfeed.Feed_Activity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.android.volley.RequestQueue info.androidhive.listviewfeed.app.AppController.getRequestQueue()' on a null object reference 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 10-31 11:00:03.570 1688-1688/info.androidhive.listvie 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime:致命异常:main 10-31 11:00:03.570 1688-1688/info.androidhive.listtime:Process E/Android.Run info androidhive.listviewfeed, PID: 1688 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: java.lang.RuntimeException: 无法启动活动 ComponentInfo{info.androidhive.listviewfeed/info.androidhive. listviewfeed.Feed_Activity}:java.lang.NullPointerException:尝试在空对象引用 10-31 11:00 上调用虚拟方法“com.android.volley.RequestQueue info.androidhive.listviewfeed.app.AppController.getRequestQueue()”: 03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime:在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) 10-31 11:00:03.570 1688-1688/info.androidhive/AndroidRuntime:at android.ActivityThread.performLaunchActivity(ActivityThread.java:2325)在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 10-31 11:00:03.570 1688-1688/info.androidhive.listvie wfeed E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:151) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5254) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at com.android.internal.os.ZygoteInit wfeed E/AndroidRuntime:在 android.app.ActivityThread.access$800(ActivityThread.java:151) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime:在 android.app.ActivityThread$H .handleMessage(ActivityThread.java:1303) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102) 10-31 11: 00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime:在 android.os.Looper.loop(Looper.java:135) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/ AndroidRuntime:在 android.app.ActivityThread.main(ActivityThread.java:5254) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime:在 java.lang.reflect.Method.invoke(Native方法)10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime:在 java.lang.reflect.Method.invoke(Method.java:372) 10-31 11:00:03.570 1688- 1688/info.androidhive.listviewfeed E/AndroidRuntime:在 com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:903) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.android.volley.RequestQueue info.androidhive.listviewfeed.app.AppController.getRequestQueue()' on a null object reference 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at info.androidhive.listviewfeed.Feed_Activity.onCreate(Feed_Activity.java:57) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5990) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at androi $MethodAndArgsCaller.run(ZygoteInit.java:903) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime:在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) ) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime:引起:java.lang.NullPointerException:尝试调用虚拟方法'com.android.volley.RequestQueue info.androidhive.listviewfeed。 app.AppController.getRequestQueue()' 对空对象引用 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at info.androidhive.listviewfeed.Feed_Activity.onCreate(Feed_Activity.java:57 ) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime:在 android.app.Activity.performCreate(Activity.java:5990) 10-31 11:00:03.570 1688-1688 .androidhive.listviewfeed E/AndroidRuntime:在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime:在 androi d.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:151) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5254) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at java.lang.refl d.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime:在 android.app.ActivityThread.access$800(ActivityThread.java:151) 10-31 11:00:03.570 1688-168 .androidhive.listviewfeed E/AndroidRuntime:在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime:在 android.os .Handler.dispatchMessage(Handler.java:102) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime:在 android.os.Looper.loop(Looper.java:135) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime:在 android.app.ActivityThread.main(ActivityThread.java:5254) 10-31 11:00:03.570 1688-1688/info.androidfeed.list E/AndroidRuntime:在 java.lang.refl ect.Method.invoke(Native Method) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) ect.Method.invoke(Native Method) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime:在 java.lang.reflect.Method.invoke(Method.java:372) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime:在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 10-31 11:00:03.58871616 /info.androidhive.listviewfeed E/AndroidRuntime:在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

Assuming that you only want one app and just want to use each of the activities and classes from the two merged packages, you can add all activity declarations from the application tag of the second package to the application tag of the manifest file of the first package.假设你只想要一个应用程序,只是想使用的每个活动和课程,从二者的合并包,您可以添加所有activity从申报application第二包的标签添加到application中的标签manifest的第一包的文件.

Now only use the manifest file of the first package, and change the app name and icon to whatever you like.现在只使用第一个包的manifest文件,并将应用程序名称和图标更改为您喜欢的任何内容。

Hope that helps, otherwise please explain what you want to achieve in more detail.希望有所帮助,否则请更详细地解释您想要实现的目标。

I've fixed it by merging the ParseApplication class into AppController class and declaring only the AppController as application into the manifest .我已经通过合并固定它ParseApplication全班分成AppController类,并声明只有AppControllerapplicationmanifest Thank you.谢谢你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM