1

I'm upgrading my old project to use latest android apis, gradle build, etc... and I'm running into this issue with my Android Manifest.

I have a few activities set like below:

<activity
            android:name="com.company.name.ui.ColorPickerActivity"
            android:label="@string/title_activity_add_photo_library"
         android:parentActivityName="com.compant.name.ui.CaptureMenuFragment"
            android:screenOrientation="portrait"
            android:theme="@style/FullscreenTheme">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.company.name.ui.CaptureMenuFragment" />
        </activity>

Where I get a error that says:

Fragment  is not assignable to 'android.app.Activity'

In reference to the android:parentActivityName above. What should it be instead? It was working in previous target api setting.

I looked through some SO posts and they mention changing Fragment to FragmentActivity but that causes other build issues like I can't use "getActivity()" method in my intent instance.

E.g: Intent intent = new Intent(getActivity(), SearchProductActivity.class);

Is there a better solution to this?

Thanks!

EDIT:

Even with regards with BindingFragmentActivity, in my manifest it says:

com.company.name.ui.ColorActivity' is not assignable to 'android.app.Activity'

After I upgrade to API 28 and Android X. What is wrong with this code in my manifest:

<activity
            android:name="com.company.name.ui.ColorActivity"
            android:label="@string/title_activity_color"
            android:parentActivityName="com.company.name.ui.ColorsActivity"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.AppCompat.NoActionBar">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.company.name.ui.ColorsActivity" />
        </activity>
Euridice01
  • 2,510
  • 11
  • 44
  • 76
  • Try removing `android:parentActivityName` and it's metadata if you do not have `Up button in the action bar` functionality. Read about it [here](https://stackoverflow.com/questions/19207762/must-i-specify-the-parent-activity-name-in-the-android-manifest) – nimi0112 Jul 14 '19 at 18:48
  • @nimi0112 I did remove the parentActivityName and metadata but it still complains – Euridice01 Jul 14 '19 at 19:06
  • Oh for the activity above in the edit, it extends: BindingFragmentActivity. What's the equivalent for Android X/Api 28. I think that's the issue. – Euridice01 Jul 14 '19 at 19:08

1 Answers1

1

There is no need to declare your fragment in the Android Manifest file. A fragment is a reusable UI component which can be attached to any activity.

A fragment takes the properties related to Screen Orientation, Theme etc from its parent Activity.

Regarding your question to change fragment to FragmentActivity, you can still access use the methods which are in FragmentActivity.

E.g: for getting the context getActivity() can be replaced with FragmentActivityName.this.

You can read more about it here.

Hope this helps. Thank you.

nimi0112
  • 2,065
  • 1
  • 18
  • 32