android - Use a button in the action bar with an intent to start a new activity -


i've got buttons in action bar so:

<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <!-- search, should appear action button --> <item android:id="@+id/action_search"     android:icon="@drawable/ic_action_search"     android:title="@string/action_search"     app:showasaction="ifroom"     android:onclick="doublebet"/> <!-- settings, should in overflow --> <item android:id="@+id/action_settings"     android:title="@string/action_settings"     app:showasaction="never" /> 

i've added onclick action_search, launch new activity. here java launch activity.

public void doublebet(view view){     intent intent = new intent(this, displaymessageactivity.class);     string x = "hello";     intent.putextra("key", x); //optional parameters     startactivity(intent);  } 

i receive intent so, in displaymessageactivity class:

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     intent intent = getintent();     string message = intent.getstringextra("key"); } 

however, app crashes when run it. cause of this?

here logcat:

https://gist.github.com/anonymous/862e5e33a10c23d3bbc9

try changing doublebet method this:

public void doublebet(view view){     intent intent = new intent(this, displaymessageactivity.class);     string x = "hello";     intent.putextra("key", x); //optional parameters     startactivity(intent); } 

to this:

public boolean doublebet(menuitem view){     intent intent = new intent(this, displaymessageactivity.class);     string x = "hello";     intent.putextra("key", x); //optional parameters     startactivity(intent);     return true; } 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

wso2esb - How to concatenate JSON array values in WSO2 ESB? -