2011-10-12 47 views
2

在我的應用程序,同時播放視頻,如果我改變手機的模式視頻不會繼續播放,但它從頭開始。我所理解的是當模式改變時活動被重新創建,我如何解決這個問題我不知道請有人幫我解決這個問題。 由於事先活動重新啓動時,電話查看模式更改

+0

找一個參數名稱onconfigchange – njzk2

+0

請您詳細介紹一下,我是新來的Android在AndroidManifest – cavallo

+0

,下activty設置onconfigchange屬性 – Blackbelt

回答

7

您可以添加這個行在您的AndroidManifest文件中添加到您的活動標籤中,這樣您的活動就不會重新啓動。

<activity android:name=".Activity_name" 
      android:configChanges="orientation|keyboardHidden"> 
+0

爲什麼我們需要添加keyboardhidden財產 – cavallo

+0

結帳此http:// developer.android.com/guide/topics/manifest/activity-element.html –

+0

這樣做不會停止orientation.It用於獲取活動中的方向更改事件.. –

4

當你的活動重新保存視頻的當前現在的位置是通過這個方法:

@Override 
public Object onRetainNonConfigurationInstance() { 
    int videoPosition = videoView.getCurrentPosition(); 
    Bundle data = new Bundle(); 
    data.putInt("POSITION", videoPosition); 
    return data; 
} 

onCreate()方法檢索此值是這樣的:

final Bundle data = (Bundle) getLastNonConfigurationInstance(); 

// The activity is starting for the first time... 
if (data == null) { 
    // start your video for the first time here.. 
} else { 
    // Resume your video from where it was left.. 
    int videoPosition = data.getInt("POSITION"); 
// start your video from videoposition....   
}