1

So, what I need here is to send data from App1 to App2. I've tried with simple code that I've made, but something is wrong here. I want to make a simple input on 1 editText in app1 then it will be received by app2.

Example :

App1 : EditText -> I input 'Hello!'

Then

App2 : TextView -> 'Hello!'

But what happens next, the textview in App2 does not show anything. What's wrong here?

These are my code that I've tried.

My Application 1:

secondAppButton = (Button)findViewById(R.id.secondAppButton);
    namaEditText = (EditText)findViewById(R.id.namaEditText);

    secondAppButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String nama = namaEditText.getText().toString();

            Intent secondApp = getPackageManager().getLaunchIntentForPackage("com.example.yosua.myapplication2");
            Bundle bundleApp = new Bundle();

            bundleApp.putString("namaOrang", nama);
            secondApp.putExtras(bundleApp);

            startActivity(secondApp);
        }
    });

My Application 2:

namaDariApp1 = (TextView)findViewById(R.id.namaApp2);

    String nama;

    Intent intent = getIntent();
    Bundle extras = intent.getExtras();

    nama = extras.getString("namaOrang");
    namaDariApp1.setText(nama);
Toshiro007
  • 77
  • 9

2 Answers2

0

Try including the key

secondApp.putExtras("key",bundleApp);

And retrieve it like this

Bundle extras = intent.getBundleExtra("key");
Melvin Mauricio
  • 387
  • 1
  • 6
0

You have to options to pass a value between two applications, The first one is by using ContentProviders are a good approach to share data between applications, or you can use a SharedPreferences something like this answer

Community
  • 1
  • 1
Abdullah AlHazmy
  • 1,299
  • 1
  • 13
  • 22