I want to implement some activities using Implicit Intent. Currently, I have a button with "Display countries" label on this button. After I click this button, the child activity is triggered and the list of countries is displayed as ListView. When I choose some country I go back to the main activity where chosen country name is displayed in a TextView and toast widget. I was able to implement these actions using explicit activity, however, I do not know how to do it with an implicit one. In particular, I am not sure what parameters to set while creating new Intent instances.
Here is the Child Activity code:
public class ChildActivity extends AppCompatActivity { ListView lvActionMode; TextView textView; Toast toast; String selectedItem; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_child); ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.items)); lvActionMode = findViewById(R.id.lvActionMode); lvActionMode.setAdapter(adapter); lvActionMode.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL ???); lvActionMode.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { selectedItem = (String) adapterView.getItemAtPosition(position); Intent replyIntent = new Intent(ChildActivity.this, MainActivity.class); replyIntent.putExtra("selectedItem", selectedItem); setResult(RESULT_OK, replyIntent); startActivity(replyIntent); } }); } } And here is the main one:
public class MainActivity extends AppCompatActivity { TextView textView; Toast toast; Intent intent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView = findViewById(R.id.textView); Context context = getApplicationContext(); int duration = Toast.LENGTH_SHORT; toast = Toast.makeText(context, "popup", duration); if (getIntent().hasExtra("selectedItem")) { textView.setText(getIntent().getStringExtra("selectedItem")); toast.setText(getIntent().getStringExtra("selectedItem")); toast.show(); } } public void sendMessage(View view){ intent = new Intent(Intent.ACTION_VIEW ???? ); startActivityForResult(intent, RESULT_OK); } } So how can I change an explicit Intent to an implicit one?