Save the state of button in Xamarin Android

后端 未结 1 1285
[愿得一人]
[愿得一人] 2021-01-27 14:37

I\'m disabling buttons once they are pressed. I want it to activate automatically the next day at 12AM. I really have no idea how to do this. Somehow I tried and written the co

相关标签:
1条回答
  • 2021-01-27 15:14

    Even though this code is in java, the concept will be the same. Once the alarm goes off, the Broadcastreceiver's onReceive is called, where you can edit the sharedpreference to enable/disable views. If you don't know about sharedpreferences, see these links: How do I use SharedPreferences in Xamarin.Android? , SharedPreferences Example in Xamarin Android

    BroadCastReceiver:

    public class ReminderActivity extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        //Use sharepreference and set the button state disabled or enabled.
        SharedPreferences mSharedPreferences = getSharedPreferences("MyPref", 0);
        mSharedPreferences..edit().putBoolean("btn_enable", true).commit();
    
    }
    }
    

    So once you open the app, check for sharedpreference value and enable or disable the button state accordingly. Hope this helps.

    0 讨论(0)
提交回复
热议问题