Try to search your question here, if you can't find : Ask Any Question Now ?

Saving an activity state when I press up button in action bar

HomeCategory: stackoverflowSaving an activity state when I press up button in action bar
kundan asked 1 week ago

I’m developing an android Wallpaper app consists of 2 activity, main activity displays the images from the internet in ListView and the second activity displays the preview of that image.
my problem is when I press the back button in preview activity to go back to the main activity, the main activity displays the images from the beginning and I would like to display the images from the last I clicked on.

The following code in onCreate() method in Main Activity:

    // Find a reference to the {@link ListView} in the layout
    ListView gameListView = findViewById(R.id.list);


    mEmptyStateTextView = findViewById(R.id.empty_view);
    gameListView.setEmptyView(mEmptyStateTextView);

    // Create a new adapter that takes an empty list of games as input
    mAdapter = new GamesAdapter(this, new ArrayList<Games>());

    // Set the adapter on the {@link ListView}
    // so the list can be populated in the user interface
    gameListView.setAdapter(mAdapter);

    // Set an item click listener on the ListView, which sends an intent to a web browser
    // to open a website with more information about the selected game.
    gameListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {


            // Find the current game that was clicked on
            Games currentGame = mAdapter.getItem(position);


            // Convert the String URL into a URI object (to pass into the Intent constructor)
            Uri gameUri = Uri.parse(currentGame.getUrl());
            String name = currentGame.getName();

            // Create a new intent to view the game URI
            Intent i = new Intent(GamesActivity.this, PreviewActivity.class);
            i.setData(gameUri);
            i.putExtra("name", name);
            startActivity(i);


        }
    });

The following code in onCreate() method in Preview Activity:

    final Uri i = getIntent().getData();
    String profile = getIntent().getStringExtra("name");
    photographer.setText(profile);

    Picasso.with(this).load(i).into(img);

    saveImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            downloadFile(i);
        }
    });
1 Answers
Best Answer
Matthias answered 1 week ago
Your Answer

9 + 0 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com