How can I call another activity from one (the current) activity?
And for the same I want to call an activity which contains a dialog message box from my current activity.
Start the Second Activity To start an activity, call startActivity() and pass it your Intent . The system receives this call and starts an instance of the Activity specified by the Intent .
You need to use Intent Class in order to redirect from one activity class to another activity class. onOptionsItemSelected() Method will be trigged when you click the 'show setting' menu in the action bar.
First question:
Use the Intent to call another Activity. In the Manifest, you should add
<activity android:name="ListViewImage"></activity> <activity android:name="com.company.listview.ListViewImage"> </activity>
And in your current activity,
btListe = (ImageButton)findViewById(R.id.Button_Liste); btListe.setOnClickListener(new OnClickListener() { public void onClick(View v) { intent = new Intent(main.this, ListViewImage.class); startActivity(intent); finish(); } });
Second question:
sendButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { String valueString = editValue.getText().toString(); long value; if (valueString != null) { value = Long.parseLong(valueString); } else { value = 0; } Bundle sendBundle = new Bundle(); sendBundle.putLong("value", value); Intent i = new Intent(Activity1.this, Activity2.class); i.putExtras(sendBundle); startActivity(i); finish(); } });
and in Activity2:
Bundle receiveBundle = this.getIntent().getExtras(); final long receiveValue = receiveBundle.getLong("value"); receiveValueEdit.setText(String.valueOf(receiveValue)); callReceiverButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent i = new Intent(Activity2.this, Receiver.class); i.putExtra("new value", receiveValue - 10); } });
check the following code to call one activity from another.
Intent intent = new Intent(CurrentActivity.this, OtherActivity.class); CurrentActivity.this.startActivity(intent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With