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
Avatarkundan asked 4 months 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(;

    mEmptyStateTextView = findViewById(;

    // 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

    // 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() {
        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.putExtra("name", name);


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

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


    saveImage.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
1 Answers
Best Answer
AvatarMatthias answered 4 months ago
Your Answer

13 + 13 =

Popular Tags

WP Facebook Auto Publish Powered By :