Home / back button causes an error due to loss of intent

I use simple intent to start a new activity and it automatically creates a home / back side. When I click this button, you should go back to the activity that caused the new activity. This action contains no information when I click this button because it is also created from an intent. Connecting the device does the job correctly.

So it looks like MainActivity> SearchResultActivity> InfoResultActivity

I can go back with a button from SearchResultsActivity to MainActivity because it doesn't need information in onCreate. SearchResultActivity needs information from MainActivity.

MainActivity

button.setOnClickListener(new View.OnClickListener()
{
    public void onClick(View v)
    {
        // Perform action on click
        String selectedVillage = villagesSpinner.getSelectedItem().toString();
        String selectedTheme = themesSpinner.getSelectedItem().toString();
        String selectedRestaurant = autocompletetextview.getText().toString();
        Log.w("tag", "" + selectedVillage + " " + selectedTheme + " " + selectedRestaurant + " " + afhaalCheck.isChecked() + " " + bezorgCheck.isChecked() + " " + uitetenCheck.isChecked());

        Intent myIntent = new Intent(MainActivity.this, SearchResultActivity.class);
        for(int i = 0; i < allFeeds.size(); i++)
        {
            if(allFeeds.get(i).name.equals(selectedTheme))
            {
                myIntent.putExtra("THEME_SEARCH", allFeeds.get(i).idNumb);
            }
        }
        myIntent.putExtra("VILLAGE_SEARCH", selectedVillage);
        myIntent.putExtra("RESTAURANT_SEARCH", selectedRestaurant);
        myIntent.putExtra("AFHAAL_CHECK", afhaalCheck.isChecked());
        myIntent.putExtra("BEZORG_CHECK", bezorgCheck.isChecked());
        myIntent.putExtra("UITETEN_CHECK", uitetenCheck.isChecked());
        startActivity(myIntent);
    }
});

      

Here I am posting information to SearchResultActivity

SearchResultActivity

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_searchresult);

            //Given values from search
             village = getIntent().getExtras().getString("VILLAGE_SEARCH");
             restaurant = getIntent().getExtras().getString("RESTAURANT_SEARCH");
             theme = getIntent().getExtras().getInt("THEME_SEARCH");
             afhaal = getIntent().getExtras().getBoolean("AFHAAL_CHECK");
             bezorg = getIntent().getExtras().getBoolean("BEZORG_CHECK");
             uiteten = getIntent().getExtras().getBoolean("UITETEN_CHECK");

....
....
....

            listView.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id)
                {
                    Intent myIntent = new Intent(SearchResultActivity.this, InfoActivity.class);
                    myIntent.putExtra("RESTAURANT_CLICKED", displayData[position].name);
                    myIntent.putExtra("RESTAURANT_SEARCHED", restaurant);
                    myIntent.putExtra("THEME_SEARCH", theme);
                    myIntent.putExtra("VILLAGE_SEARCH", village);
                    myIntent.putExtra("AFHAAL_CHECK", afhaal);
                    myIntent.putExtra("BEZORG_CHECK", bezorg);
                    myIntent.putExtra("UITETEN_CHECK", uiteten);
                    startActivityForResult(myIntent,0);
                }
            });
.....
....

      

Here I am sending the search information and the name of the clickView listView to the InfoActivity to tell it what to display.

Now in InfoActivity I tried to use finish () method to send something back, but it doesn't work for home / backbutton. The problem is that finish () is not called when I press the home / backbotton button.

InfoActivity

@Override
public void finish()
{
    // Prepare data intent
    Intent myIntent = new Intent();
    myIntent.putExtra("THEME_SEARCH", getIntent().getExtras().getString("THEME_SEARCH"));
    myIntent.putExtra("VILLAGE_SEARCH", getIntent().getExtras().getString("VILLAGE_SEARCH"));
    myIntent.putExtra("RESTAURANT_SEARCH", getIntent().getExtras().getString("RESTAURANT_SEARCH"));
    myIntent.putExtra("AFHAAL_CHECK",getIntent().getExtras().getString("AFHAAL_CHECK") );
    myIntent.putExtra("BEZORG_CHECK", getIntent().getExtras().getString("BEZORG_CHECK"));
    myIntent.putExtra("UITETEN_CHECK",getIntent().getExtras().getString("UITETEN_CHECK") );
    // Activity finished ok, return the data
    setResult(RESULT_OK, myIntent);
    super.finish();
}

      

+3


source to share





All Articles