如何停止android应用程序kill上的所有服务、线程和卸载库

如何停止android应用程序kill上的所有服务、线程和卸载库,android,android-service,kill,kill-process,android-thread,Android,Android Service,Kill,Kill Process,Android Thread,我想让用户能够选择不同语言的应用程序界面和内容的语言。 我想用用户选择的新语言从服务器重新加载新的本地化数据 要使用新的语言设置重新创建应用程序,我计划: 将所选语言保存到共享首选项 对我的两个IntentService调用stopService() 使用下面的答案完全杀死当前正在运行的应用程序: 在MyApplication启动时,首先检查共享首选项以及它们是否包含新的用户语言,然后清除SharedReferences、Realm数据库中的几乎所有记录 再次启动所有服务,现在它们将转到服务器并

我想让用户能够选择不同语言的应用程序界面和内容的语言。 我想用用户选择的新语言从服务器重新加载新的本地化数据

要使用新的语言设置重新创建应用程序,我计划:

  • 将所选语言保存到共享首选项
  • 对我的两个IntentService调用stopService()
  • 使用下面的答案完全杀死当前正在运行的应用程序:
  • 在MyApplication启动时,首先检查共享首选项以及它们是否包含新的用户语言,然后清除SharedReferences、Realm数据库中的几乎所有记录
  • 再次启动所有服务,现在它们将转到服务器并获取具有新语言首选项的新数据
  • 关于应用程序终止,我想了解的是下一步:

  • 在终止当前正在运行的应用程序时-所有正在运行的
    服务、线程、线程执行器、CompositeDisposable、WorkEnqueuer、Runnable、AsyncTasks、Handler
    以及所有线程和(在后台工作)内容是否将与
    系统同时停止。退出(0)
    将被调用吗?这是否意味着当我关闭我的应用程序时,它也会立即完全停止所有与线程相关的工作

  • 我使用的所有库是否都将从内存中卸载,然后在第二次启动时正确地重新初始化?像这样的库:
    RealmDB、Firebase、Dagger、RxJava2、改型
    ?下面列出了我在项目中使用的库和服务列表

  • 所有静态变量都将重新初始化吗

  • 谢谢

    以下是我使用的清单和库:

    <application
            android:allowBackup="false"
            android:hardwareAccelerated="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:largeHeap="true"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:name=".application.MyApplication"
            android:theme="@style/AppTheme"
            tools:replace="android:allowBackup">
    
        <activity
                android:name=".view.activity.SplashActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait"
                android:launchMode="singleTask"
                android:theme="@style/Theme.AppCompat.Translucent">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
        <service android:name=".services.MyFirebaseMessagingService">
                <intent-filter>
                    <action android:name="com.google.firebase.MESSAGING_EVENT" />
                </intent-filter>
            </service>
    
            <service android:name=".services.MyFirebaseInstanceIDService">
                <intent-filter>
                    <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
                </intent-filter>
            </service>
    
        <receiver android:name="com.appsflyer.MultipleInstallBroadcastReceiver" android:exported="true">
                <intent-filter>
                    <action android:name="com.android.vending.INSTALL_REFERRER" />
                </intent-filter>
            </receiver>
    
        <receiver android:name="io.branch.referral.InstallListener" android:exported="true">
                <intent-filter>
                    <action android:name="com.android.vending.INSTALL_REFERRER" />
                </intent-filter>
            </receiver>
    
            <receiver
                android:name="com.google.android.gms.analytics.AnalyticsReceiver"
                android:enabled="true">
                <intent-filter>
                    <action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
                </intent-filter>
            </receiver>
    
    
        <service
                android:name="com.google.android.gms.analytics.AnalyticsService"
                android:enabled="true"
                android:exported="false" />
    
            <receiver
                android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
                android:enabled="true"
                android:exported="false"/>
    
            <receiver
                android:name="com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver"
                android:enabled="true"
                android:permission="android.permission.INSTALL_PACKAGES">
                <intent-filter>
                    <action android:name="com.android.vending.INSTALL_REFERRER" />
                </intent-filter>
            </receiver>
    
        <service
                android:name="com.google.android.gms.measurement.AppMeasurementService"
                android:enabled="true"
                android:exported="false" />
    
        <service
                android:name=".services.MyIntentService"
                android:enabled="true"
                android:exported="false" />
            <service
                android:name=".services.MyJobIntentService"
                android:exported="false"
                android:permission="android.permission.BIND_JOB_SERVICE" />
    
    </application>
    

    如果调用
    system.exit()
    ,则承载应用程序的操作系统进程将死亡。这将被视为“应用程序崩溃”,并且可能会向用户显示一个对话框,表明这一点。这不是一种用户友好的关闭应用程序的方法,在Android上也不是通常的方法

    在任何情况下,您的所有代码都将停止运行(所有线程),所有库都将被卸载,所有静态变量都将被清除,因为操作系统进程将死亡,并且它们都将消失

    com.google.dagger:dagger
    com.jakewharton:butterknife
    io.reactivex.rxjava2:rxjava
    com.github.bumptech.glide:glide
    com.google.code.gson:gson
    com.squareup.retrofit2:retrofit
    com.facebook.android:facebook-android-sdk
    com.google.android.gms:play-services-auth
    com.google.firebase:firebase-core
    io.realm:realm-gradle-plugin