Intent is not working for moving fragment to activity

Mohit Lakhanpal :

I'm having trouble moving intent class fragment to activity. I'm trying to send intent from one Fragment to another Activity. Here is the code:

        Intent intent = new Intent(getActivity(), MainActivity.class);
        getActivity().startActivity(intent);

Here is my Manifest File

    <activity android:name=".activities.MainActivity"
        android:supportsPictureInPicture="true"
        android:resizeableActivity="true"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustNothing"
        android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"/>

but it's not working for me and on another side, I have done some RND but all are same for me. How can I Solve the issue Thanks In Advance.

Quick learner :

remove this android:launchMode="singleTask" which looks like this

<activity android:name=".activities.MainActivity"
        android:supportsPictureInPicture="true"
        android:resizeableActivity="true"
        android:windowSoftInputMode="adjustNothing"
        android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"/>

if your current activity is mainactivity and you are launching it again , it will not work because launchmode is set to single task in manifest

Solution :- remove this tag

android:launchMode="singleTask"

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=133598&siteId=1