Comments (6)
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.
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.
You mean this? Main extends it.
from colorful.
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.
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.
Can you fix the formatting issues and tell what you changed, please?
from colorful.
Related Issues (20)
- Not working after app restart HOT 4
- Use custom color HOT 11
- Load style resources by name not by id
- "setPrimaryColor" and "setCustomThemeOverride" conflict HOT 12
- Disabled override how to use light/dark theme HOT 1
- Request to add color HOT 3
- Use THEME_MATERIAL appear error log HOT 10
- Colorful has error when start strict mode HOT 7
- Some times primaryColor and accentColor are not used HOT 9
- Sample code for use without kotlin HOT 5
- Compile issue error: style attribute 'attr/colorSecondary HOT 11
- Does Proguard settings mentioned in document?
- Material Drawer Theming Support? HOT 3
- Migrate to AndroidX HOT 1
- How to customize views in theme?
- ThemeEditor public apply method needs null check
- startSupportActionMode works not propertly with Colorful
- ERROR: Failed to resolve: com.github.garretyoder:Colorful:2.3.4 HOT 1
- R styles not found on API 19 HOT 1
- App bar and Statusbar need same color HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from colorful.