Question

I am having some trouble traveling from Activities A->B->A after B is restarted. How do I restart activity B without messing up how the intent is returned to A after B is finished?

B is called from A with this code:

    public void activityFunction(Context gameContext){
    //This function was made to pass the player class back and forth between 

    setContentView(R.layout.loadingscreen);
    Intent i = new Intent(gameContext, gamePanel.class);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivityForResult(i,1);
    }

The B game activity is reset with this code:

        setContentView(R.layout.loadingscreen);
        Intent i = getIntent();
        finish();
        startActivity(i);

B finishes and returns to A with this code:

    public void levelOver(){
        setContentView(R.layout.loadingscreen);
        Intent resultIntent = new Intent();
        resultHolder results = new resultHolder(playerStats);
        resultIntent.putExtra(.......);
        resultIntent.putExtra(.......);
        resultIntent.putExtra(.......);
        resultIntent.putExtra(.......);
        setResult(Activity.RESULT_OK, resultIntent);
        finish();
        }

And here is where onActivity is called in A

protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch(requestCode) {
    case (1) : {
         if (resultCode == Activity.RESULT_OK) {
         returnedWithResults = true;
         new AsyncReturnGameData().execute(data);
      }
      break;
    } 
  }
}

Activity B returns 100% of the time as long as it is not restarted. When it is restarted, it returns an error. Any help pointing me in the right direction would be greatly appreciated. Thanks!

Was it helpful?

Solution

try to change this:

 setContentView(R.layout.loadingscreen);
        Intent i = getIntent();
        finish();
        startActivity(i);

to this:

 setContentView(R.layout.loadingscreen);
    Intent i = getIntent();       
    startActivity(i);
    finish();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top