Is it possible to implement such Activity behaviour?

59 Views Asked by At

There are two Activities: ActivityA and ActivityB.

From ActivityA I going to ActivityB. Then, I choose some list item and going back to Activity A(same instance) with selected data. And the most difficult: if I press back now, I should going back to ActivityB(with same instance and with saved View state).

Is it possible to implement? Not necessary via launchMode attribute, perhaps there is another way to manage Activities manually via ActivityManager.

2

There are 2 best solutions below

1
On

Use startActivityForResult to get the result from activity B which was started by activity A. Activity B returns result when it is finished.

2
On

In onActivtyResult of Activity put boolean flag so that you can check that it comes after selecting data from Activity B and in onBackPressed of Activity A start Activity B

like this way

boolean flag = false;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        flag = true;
    }

    @Override
    public void onBackPressed() {
        // TODO Auto-generated method stub

        if(flag)
        {
            //Start Activity B
        }
        else
        {
            // finish this activity
        }

    }