Error in settings activity

253 views
Skip to first unread message

Nikhil Patil

unread,
Sep 22, 2020, 11:18:12 AM9/22/20
to android-porting
Hi,
I've added an activity in settings android manifest file and also created a class for that. When I build an image and install on device I'm able to see that option but when I click on that, the settings app crashes and in logcat getting error as -

Note: I've created an event in MetricsEvent class and in metrics_constants.proto

Process: com.android.settings, PID: 1849
    java.lang.RuntimeException: Unable to pause activity {com.android.settings/com.android.settings.Settings}: java.lang.IllegalArgumentException: Must define metric category

Here's my manifest

<activity
android:name="Settings$PowerOptions"
android:label="@string/power_info_title"
android:icon="@drawable/ic_homepage_power"
android:taskAffinity="com.android.settings"
android:parentActivityName="Settings">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE_LAUNCH" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
<intent-filter android:priority="7">
<action android:name="com.android.settings.action.SETTINGS" />
</intent-filter>
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.ia.homepage" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.PowerOptions" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
<meta-data android:name="com.android.settings.summary"
android:resource="@string/power_info_description"/>
</activity>

and my class -

public class PowerOptions extends SettingsPreferenceFragment {

private static final String TAG = "PowerSettings";

@Override
public int getMetricsCategory() {
return MetricsEvent.POWER_OPTIONS;
}

@Override
public int getHelpResource() {
return 0;
}

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.device_power_settings);
}
}
Reply all
Reply to author
Forward
0 new messages