简体   繁体   中英

How to Activate Button?

my context menu has two options Silly and Cool. I want to provide one item named activate to list item silly and second item named deactivate to list item cool. How can i do that.?????? Help

You can use intent.putExtra - put some information there, for example some object, String, whatever you want.

Then in your second activity just get those extras by

Bundle extras = getIntent().getExtras();

And for example if u have some boolean stored then you do:

boolean something = extras.getBoolean("keyToThatBoolean");

1.If you want to start the second activity (and activate the settings) when Activate button is pressed you can use Intent to send a String or Integer (0 or 1) to know in the second activity that button was pressed.

You can find more information about sending data with Intent here

2.If you don't want to start the second activity when button is pressed but still activate the settings, you can make another class(Utils.java) where you can define all your settings (vibration, volume, ringtone) in methods and call them like that:

Utils mUtils = new Utils(); mUtils.activateVibration(); mUtils.playRingTone(); mUtils.setVolume(volumeLevel);

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM