Code Monkey home page Code Monkey logo

Comments (6)

Elvis10ten avatar Elvis10ten commented on May 22, 2024 1

Sorry, i changed only the code in onResume from:

@Override
    protected void onResume() {
        super.onResume();
        if (!Colorful.getThemeString().equals(themeString)) {
            Log.d(Util.LOG_TAG, "Theme change detected, restarting activity");
            recreate();
        }
    }

to

protected void onResume() {
        super.onResume();
        if(!Colorful.getThemeString().equals(mThemeString)) {
            Log.d(LOG_TAG, "Theme change detected, restarting activity");
            recreateActivity();
        }
    }

    private void recreateActivity() {
        //Delaying activity recreate by 1 millisecond. If the recreate is not delayed and is done
        // immediately in onResume() you will get RuntimeException: Performing pause of activity that is not resumed
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                recreate();
            }
        }, 1);
    }

Still new to git so don't know how to submit my fix so am posting this here. The idea is to delay the call to recreate() in onResume() by using handler postDelayed method

from colorful.

meierjan avatar meierjan commented on May 22, 2024

Performing pause of activity that is not resumed

Can you link the version of your MainActivity here? I see your project is open source

from colorful.

DanteAndroid avatar DanteAndroid commented on May 22, 2024

You mean this? Main extends it.

from colorful.

Elvis10ten avatar Elvis10ten commented on May 22, 2024

I experience the same issue. I believe the problem is cause by the recreate call in onResume of ColorfulActivity. The solution is to slightly delay the recreate call using a handler. Found this answer on stackoverflow, might help: http://stackoverflow.com/questions/10844112/runtimeexception-performing-pause-of-activity-that-is-not-resumed

from colorful.

Elvis10ten avatar Elvis10ten commented on May 22, 2024

This fixed it for me

`import android.app.ActivityManager.TaskDescription;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;

import org.polaric.colorful.Colorful;

public abstract class ColorfulActivity extends AppCompatActivity {

    private static final String LOG_TAG = "ColorfulActivity";

    private String mThemeString;

    public ColorfulActivity() {
    }

    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mThemeString = Colorful.getThemeString();
        setTheme(Colorful.getThemeDelegate().getStyle());

        if(VersionUtils.hasLollipop()) {
            if(Colorful.getThemeDelegate().isTranslucent()) {
                LogUtils.d(LOG_TAG, "Translucent status bar is enabled");
                this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            }

            TaskDescription tDesc = new TaskDescription(null, null,
                    ContextCompat.getColor(this, Colorful.getThemeDelegate().getPrimaryColor().getColorRes()));
            setTaskDescription(tDesc);
        }
    }

    protected void onResume() {
        super.onResume();
        if(!Colorful.getThemeString().equals(mThemeString)) {
            LogUtils.d(LOG_TAG, "Theme change detected, restarting activity");
            recreateActivity();
        }
    }

    private void recreateActivity() {
        //Delaying activity recreate by 1 millisecond. If the recreate is not delayed and is done
        // immediately in onResume() you will get RuntimeException: Performing pause of activity that is not resumed
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                recreate();
            }
        }, 1);
    }
    
    public String getThemeString() {
        return mThemeString;
    }
    
}
`

from colorful.

meierjan avatar meierjan commented on May 22, 2024

Can you fix the formatting issues and tell what you changed, please?

from colorful.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.