0

I ask if I can pass to an other application some data using intent. If it's possible, how can I do clicking a button and passing to an other application?

b1.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View arg0) {
        Intent intention = new Intent(?????);

        startActivity(intention);
        }
});
greywolf82
  • 20,269
  • 17
  • 45
  • 90
user3714257
  • 47
  • 1
  • 6

1 Answers1

0

To pass data from one activity to another you need to add it to the Intent. E.g,

Intent intention = new Intent(this, DestClass.class);
int value = 10;
intention.putExtra("KEY", value);
startActivity(intention);

and in your DestClass's onCreate(), you get it from the Intent with,

Bundle extras = getIntent().getExtras();
if (extras!= null) {
   extras.getInt("KEY");
}

To send it to another application. Similarly you create an Intent as shown in the Android docs.

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);

Note that in this case the Android system allows apps to register to receive Intents and if there are multiple apps that have registered for these Intents then the system lets the user choose which App they would like to handle the Intent.

source.rar
  • 7,632
  • 9
  • 45
  • 79