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
-
Well you can use **Intent** to call second activity and your question is confusing which button you are talking about button in first activity or button present in second activity – Sanjeev Jul 31 '15 at 13:09
-
Button means by clicking context item 1. – shani jani Jul 31 '15 at 13:11
-
What will be the code of intent? – shani jani Jul 31 '15 at 13:11
-
startActivity(new Intent(Profile.this, Custom.class)); you have used it already use put extra feature to make your calling custom – Sanjeev Jul 31 '15 at 13:16
2 Answers
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");

- 94
- 1
- 1
- 5
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!
-
Thanx for your guidence.Please tell me where i should add this piece of code. In my profile file or in custom ? Or should i create this class seperately? – shani jani Jul 31 '15 at 17:30
-
You should create Utils class separately so you can acces it from any activity you want. – Chris Aug 01 '15 at 06:35
-
Now there is a little issue. After activation it opens a blank activity but i do not need this activity. I just want to redirect it to activity back the activity from which it was called !! Help me.. – shani jani Aug 01 '15 at 11:37
-
How did you created your Utils class? New Java class or New Blank Activity? I think you created another activity and you put all the code in `onCreate` method. If you did like that it's wrong. `You need to create a New Java Class`, not Activity. Tell me how you did it. – Chris Aug 01 '15 at 12:32
-
I created new java class that extends activity. But i did not write any setContext() .yea i called my playRingTone() in onCREATE method. – shani jani Aug 01 '15 at 15:09
-
Dont extend Activity, create a clean class. Your blank activity appears because you extended Activity and start the window with Intent at button pressing. – Chris Aug 01 '15 at 16:37
-
If you think I helped you please accept my answer as the correct one, or give it an Up Vote – Chris Aug 10 '15 at 09:59