Search code examples
androidandroid-activityandroid-recyclerviewandroid-cardview

How to create a card view in activity A on button click from Activity B


In my project the requirement is to create a recycler view -> card view inactivity A when information is filled and the button is pressed in activity B.

The filled information in activity B should be passed to Activity A recycler view -> card view.

I know how to create a card view on button click but don't have an answer to my question.

I'm new to android development and kindly help me with solutions for this. Million thanks in advance!


Solution

  • If you first show Activity A then show Activity B so you can use ActivityResult but if you first show Activity B and user fill the information then show Activity A you can pass data with Intent in Activity B :

    Intent intent = new Intent(ActivityB.this, ActivityA.class);
    intent.putExtra("information_name", "Saptha");
    intent.putExtra("information_last_name", "Clans"); 
    startActivity(intent);
    

    then in your Activity A get data like this and insert in your list :

    String name = getIntent().getStringExtra("information_name");
    String lastName = getIntent().getStringExtra("nformation_last_name");