-2

I have a page product to which overtime u press a button a different id is sent through intent.There is a buy button in this page if we are not logged in it will take us to login page so after I login how to I go back to this page with the same id that was passed to this intent.

Abdul Wasae
  • 3,614
  • 4
  • 34
  • 56
Ciddarth Raaj
  • 55
  • 1
  • 6

2 Answers2

0

Start the login activity using startActivityForResult() method.

When your work is done in login activity then call setResult(RESULT_OK) and call finish() to finish that activity.

You will get back to your previous activity. There you have to override the onActivityResult() method if you want to do something.

Avijit Karmakar
  • 8,890
  • 6
  • 44
  • 59
0

Suppose If you are clicking on Button click event

Button button=new Button(getApplicationContext());
    button.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            Intent intent=new Intent(getApplicationContext(),LoginActivity.class);
            intent.putExtra("yourid","123");
            intent.putExtra("goingtologin","true");
            startActivity(intent);
        }
    });
    if(getIntent().getStringExtra("yourid")!=null)
    {
        String id=getIntent().getStringExtra("yourid");
    }


    //in your login activity

    String iscomingfromlogin="";
    String id="";
    if(getIntent().getStringExtra("goingtologin")!=null)
    {
        iscomingfromlogin=getIntent().getStringExtra("goingtologin");
    }
    id=getIntent().getStringExtra("yourid");

    // after login successfully check


    if(iscomingfromlogin.equals("true"))
    {
        Intent intent=new Intent(getApplicationContext(),YOURPREVIOUSACTIVITY.class);
        intent.putExtra("yourid",id);
        startActivity(intent);
        finish();
    }
Vishal Senjaliya
  • 454
  • 6
  • 21
MageNative
  • 682
  • 5
  • 14