WAI
Status Update
Comments
ar...@google.com <ar...@google.com>
ar...@google.com <ar...@google.com> #2
Thank you for reporting this issue. For us to further investigate this issue, please provide the following additional information:
Steps to reproduce
Please provide source code or apk of a sample application to reproduce the issue.
Also kindly mention the steps to be followed for reproducing the issue with the given sample application.
Frequency
How frequently does this issue occur? (e.g 100% of the time, 10% of the time)
Expected output
What is the expected output?
Current output
What is the current output?
Steps to reproduce
Please provide source code or apk of a sample application to reproduce the issue.
Also kindly mention the steps to be followed for reproducing the issue with the given sample application.
Frequency
How frequently does this issue occur? (e.g 100% of the time, 10% of the time)
Expected output
What is the expected output?
Current output
What is the current output?
pr...@gmail.com <pr...@gmail.com> #3
Here is the provided sample app.
Steps to reproduce
Open provided sample app, click on "Open preferences" button.
Frequency
It's 100% reproducible with this app
Expected output
Open Preferences without crashing obviously
Current output
Crashing with "java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx/xxx.preferences.PreferencesActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewGroup.setLayoutTransition(android.animation.LayoutTransition)' on a null object reference"
I've actually managed to pinpoint the problem here. It's related to "setContentView(R.layout.layout_preferences);" method in which I'm providing preference activity with custom toolbar layout. Once this line is removed, the code does not crash anymore. This worked properly in all versions prior to O preview.
Steps to reproduce
Open provided sample app, click on "Open preferences" button.
Frequency
It's 100% reproducible with this app
Expected output
Open Preferences without crashing obviously
Current output
Crashing with "java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx/xxx.preferences.PreferencesActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewGroup.setLayoutTransition(android.animation.LayoutTransition)' on a null object reference"
I've actually managed to pinpoint the problem here. It's related to "setContentView(R.layout.layout_preferences);" method in which I'm providing preference activity with custom toolbar layout. Once this line is removed, the code does not crash anymore. This worked properly in all versions prior to O preview.
pr...@gmail.com <pr...@gmail.com> #4
Hmm, I don't see the attached zip file, but I guess you can since it displayed a popup that message is created with 1 attachment.
ar...@google.com <ar...@google.com> #5
Thank you for reporting this issue. We have shared this with our engineering team and will update this issue with more information as it becomes available.
ar...@google.com <ar...@google.com> #6
There are a few things that are being implemented incorrectly in the given project:
1) Extending PreferenceActivity and overriding its content view by "setContentView(R.layout.layout_preferences)" means that the PreferenceActivity doesn't have the views it needs to layout its stuff. This is the reason for the exception.
2) Using headers but not providing fragments for them.
3) Using headers and trying to have a simple list of preferences at the same time.
We would recommend you to read more about preferences inhttps://developer.android.com/guide/topics/ui/settings.html and follow the instructions there.
1) Extending PreferenceActivity and overriding its content view by "setContentView(R.layout.layout_preferences)" means that the PreferenceActivity doesn't have the views it needs to layout its stuff. This is the reason for the exception.
2) Using headers but not providing fragments for them.
3) Using headers and trying to have a simple list of preferences at the same time.
We would recommend you to read more about preferences in
pr...@gmail.com <pr...@gmail.com> #7
1) WTF? This worked in all Androids from 14 to 24 on all phones we tested. The app is used in an environment of hundreds of thousands. If this was wrong it wouldn't work in the first place. The whole point of setContentView method is to override the default layout.
2) This was an example app, I didn't want to waste time creating fragments. Our app has all the required components properly implemented.
3) Not sure what you mean with this.
I've been an Android developer for 7 years and you're basically telling me to RTFM. Not cool dude. Every time a new Android OS arrives, you guys fuck things up with all the changes and restrictions and introduced bugs which we have to fix/override/rewrite so our apps won't remain broken.
It would be better for you to tell me what the hell you changed in PreferenceActivity that breaks this code, so I can again fix your mess in my code, if you're unable to fix it or just don't care. If it was intended behavour, it wouldn't work at all.
2) This was an example app, I didn't want to waste time creating fragments. Our app has all the required components properly implemented.
3) Not sure what you mean with this.
I've been an Android developer for 7 years and you're basically telling me to RTFM. Not cool dude. Every time a new Android OS arrives, you guys fuck things up with all the changes and restrictions and introduced bugs which we have to fix/override/rewrite so our apps won't remain broken.
It would be better for you to tell me what the hell you changed in PreferenceActivity that breaks this code, so I can again fix your mess in my code, if you're unable to fix it or just don't care. If it was intended behavour, it wouldn't work at all.
ar...@google.com <ar...@google.com> #8
Below is the information shared by Engineering team for your above queries.
The "setContentView" method was created so any class implementing directly the Activity class can provide it with its content view (see first chapter inhttps://developer.android.com/reference/android/app/Activity.html ). Overriding that in another inherited activity is dangerous since you cannot know how the parent activity works with the views it expects to get.
It is possible that it worked for you previously but this was never intentionally supported / documented or even recommended. We need to be able to modify the layout of PreferenceActivity to keep it up to date with the rest of the platform. PreferenceActivity should be used in the way that you provide it with a list of your preferences and it shows them. It can also show headers to manage categories for you. You should not care about how it internally organizes its layout or trying to modify that. If you want to design your own Activity you can just use PreferenceFragment to get the list of preferences and put it to your activity. Again, all of this is described in the documentation athttps://developer.android.com/guide/topics/ui/settings.html . There is also support library implementation if needed.
The "setContentView" method was created so any class implementing directly the Activity class can provide it with its content view (see first chapter in
It is possible that it worked for you previously but this was never intentionally supported / documented or even recommended. We need to be able to modify the layout of PreferenceActivity to keep it up to date with the rest of the platform. PreferenceActivity should be used in the way that you provide it with a list of your preferences and it shows them. It can also show headers to manage categories for you. You should not care about how it internally organizes its layout or trying to modify that. If you want to design your own Activity you can just use PreferenceFragment to get the list of preferences and put it to your activity. Again, all of this is described in the documentation at
pr...@bookkeeperapp.net <pr...@bookkeeperapp.net> #9
Hi Reporter, I am facing the same issue in my app on Android Oreo. Since Google is not going to fix this, what solution did you come up with? please share the solution on this thread.
pr...@gmail.com <pr...@gmail.com> #10
This is the solution I used for this problem. It's a bit hacky, but it works. For how long will it work, I cannot guess.
// inflate preference list content
LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent();
// inflate custom activity view
View parent = LayoutInflater.from(this).inflate(R.layout.activity_base, null);
// add preference list to activity
FrameLayout content = (FrameLayout) parent.findViewById(R.id.content);
if (content != null) {
if (root.getParent() != null) {
((ViewGroup)root.getParent()).removeAllViews();
}
content.addView(root);
}
// set new root view to activity base with preference list content
setContentView(parent);
// inflate preference list content
LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent();
// inflate custom activity view
View parent = LayoutInflater.from(this).inflate(R.layout.activity_base, null);
// add preference list to activity
FrameLayout content = (FrameLayout) parent.findViewById(R.id.content);
if (content != null) {
if (root.getParent() != null) {
((ViewGroup)root.getParent()).removeAllViews();
}
content.addView(root);
}
// set new root view to activity base with preference list content
setContentView(parent);
Description
I'm testing our app for Android O compatibility and found a crash that prevents the user to open PrefrencesActivity.
I used Android studio 2.4 preview and updated all support libraries used by the project to 26.0.0-alpha1.
This is the code for our preferences:
public class PreferencesActivity extends AppCompatPreferenceActivity {
@Override
public void onBuildHeaders(List<Header> target) {
setContentView(R.layout.layout_preferences);
loadHeadersFromResource(R.xml.preferences_main, target);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(R.string.preference_title);
}
}
}
Every time the I try to open preferences, I get a crash:
java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx/xxx.preferences.PreferencesActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewGroup.setLayoutTransition(android.animation.LayoutTransition)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2805)
at android.app.ActivityThread.-wrap12(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1537)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6408)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:232)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewGroup.setLayoutTransition(android.animation.LayoutTransition)' on a null object reference
at android.preference.PreferenceActivity.onCreate(PreferenceActivity.java:643)
at com.mavenir.android.activity.AppCompatPreferenceActivity.onCreate(AppCompatPreferenceActivity.java:45)
at android.app.Activity.performCreate(Activity.java:6767)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1195)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2699)
... 9 more
If I try to open preferences by loading a fragment inside PreferencesActivity (not using headers), I get no crash and Preferences load properly.