2016-12-21 81 views
2

在我的多語言應用程序中,我想從啓動程序活動重新啓動我的應用程序。但我無法這樣做。我已經通過移除如何銷燬應用程序的區域設置更改

區域

的Android改變了應用程序清單:configChanges = 「方向| keyboardHidden」

,但它不是工作我。 清單:

<application 
     android:name=".Global.MyApp" 
     android:allowBackup="true" 
     android:icon="@drawable/login_meter" 
     android:label="@string/app_name" 
     android:largeHeap="true" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
..... 
..... 
<activity 
      android:name=".SplashActivity" 
      android:configChanges="orientation|keyboardHidden" 
      android:launchMode="singleTask" 
      android:screenOrientation="portrait" 
      android:theme="@style/SplashTheme" 
      > 
      <intent-filter> 
       .... 

      </intent-filter> 
     </activity> 

.... 
.... 

</application> 
+0

http://stackoverflow.com/questions/8049207/how-to-refresh-activity-after-changing-language-locale-inside -應用 – HsRaja

回答

1

沒有爲區域設置一個Intent 變化的行動。 你應該註冊BroadcastReceiver來抓住這個意圖,並在onReceive()方法中做任何你想做的事情。

0

我有一個解決方法,但做到這一點在你的活動

/** 
*create BroadcastReciever to listen for local changes 
**/ 
private BroadcastReceiver myReceiver = new BroadcastReceiver() { 

      @Override 
      public void onReceive(Context context, Intent intent) { 
       String locale = Locale.getDefault().getCountry(); 
       finish(); 
      } 
     }; 


/** 
* Register to BroadcastReciever on Resume 
**/ 
@Override 
    protected void onResume() { 

     IntentFilter filter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED); 
     registerReceiver(myReceiver, filter); 
     Log.d(TAG,"resume"); 
     super.onResume(); 
    } 

/** 
* unsubscribe from BroadcastReciever onDestroy 
**/ 

@Override 
    protected void onDestroy() { 

     try { 
      unregisterReceiver(myReceiver); 
     } catch(IllegalArgumentException e) { 
      Log.d(TAG,"RECIEVER UNREGISTER ERROR"); 
     } 
     super.onDestroy(); 

    } 
相關問題