0

アラーム アプリで作業していますが、私のレイアウトには、ユーザーが何かを思い出させたい時間を設定するために使用される TimePicker ビューが含まれています。アクティビティがバックグラウンドに送信されているときに値を保存する際に適用されるメソッドに問題があるようです。コンパイラのコードはエラーなしできれいですが、スマートフォンでデバッグするときはアプリケーションをバックグラウンドに送り、再開するとTimePickerの現在の時間はこれら2つの方法によって変更されません...あなたの時間と貢献は高く評価

 class SecondActivity : AppCompatActivity
    {
      TimePicker timePicker2;
       int x=2;
       protected override void OnCreate(Bundle savedInstanceState)
        {
         base.OnCreate(savedInstanceState);
         //Timepicker definition
         timepicker1=this.FindViewById<TimePicker>(Resource.Id.timepicker1);
          //Setting the default selected time of the Timepicker via OnCreate
        timepicker1.CurrentHour=Java.Lang.Integer.ValueOf(x);

        }
     //This method supposedly overrides another method called OnSavedInstanceState and allows programmer to save values to it
      protected override void OnSaveInstanceState(Bundle savedInstanceState)
        {
            int y;
            y = 2;
         //Saving my value to Bundle savedInstanceState
            savedInstanceState.PutInt("value",y);
           //This super is being called but i dont know what it does
            base.OnSaveInstanceState(savedInstanceState);
        }
     //This method is supposed to remember all the values user saved before the Activity went into OnPause()
//Changed this from public to protected because i figured onsavedInstanceState has its parameters protected so unless its an inheritance, access to its members is forbidden
        protected override void OnRestoreInstanceState(Bundle savedInstanceState)
        {
            base.OnRestoreInstanceState(savedInstanceState);
            //Restore the time value from the SavedInstance state
            int c = savedInstanceState.GetInt("value");
           //Assign the value to The Timepicker
            timePicker2.CurrentHour=(Java.Lang.Integer.ValueOf(c));
        }
}````
What am i doing wrong? An additional alert dialog code to detect when activity goes into Onpause and OnRestore will greatly be appreciated
4

1 に答える 1