× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Getting the button id that leads to a new activity - android

Xaver Kapeller
Mar 13, 2015
<p>Why don't you just add the id to the <code>Intent</code> as an extra? Like this:</p> <pre><code>Intent intent = new Intent(getActivity(), NewActivity.class); intent.putExtra("button_id", button.getId()); startActivity(intent); </code></pre> <p>You can then retrieve the id in the new <code>Activity</code> like this:</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Intent intent = getIntent(); int buttonId = intent.getIntExtra("button_id", 0); ... } </code></pre> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/25486219/Getting%20the%20button%20id%20that%20leads%20to%20a%20new%20activity%20-%20android/25486282">Stack Overflow</a>.</p>

Get New Tutorials Delivered to Your Inbox

New tutorials will be sent to your Inbox once a week.

comments powered by Disqus