Loading a fragment upon a specific condition












0















I have an issue please help me out. I am building an android application and I have successfully integrated Rewarded video ads to it.



I want to show a fragment or auto redirect to a specific fragment when the below condition is met:



@Override
public void onRewarded(RewardItem rewardItem) {
// I want to redirect the user to a particular fragment here.
}


So Please help me out, if there is any other way to achieve this then please let me know.










share|improve this question

























  • So what is the issue ? Don't you aware of FragmentTransaction with FragmentManager?

    – Piyush
    Nov 21 '18 at 11:13











  • I am just starting out with android kindly help me.

    – Syed Naveed
    Nov 21 '18 at 11:14











  • Check this

    – Piyush
    Nov 21 '18 at 11:15











  • Possible duplicate of having a condition to fragment adding

    – Hossam Hassan
    Nov 21 '18 at 11:22
















0















I have an issue please help me out. I am building an android application and I have successfully integrated Rewarded video ads to it.



I want to show a fragment or auto redirect to a specific fragment when the below condition is met:



@Override
public void onRewarded(RewardItem rewardItem) {
// I want to redirect the user to a particular fragment here.
}


So Please help me out, if there is any other way to achieve this then please let me know.










share|improve this question

























  • So what is the issue ? Don't you aware of FragmentTransaction with FragmentManager?

    – Piyush
    Nov 21 '18 at 11:13











  • I am just starting out with android kindly help me.

    – Syed Naveed
    Nov 21 '18 at 11:14











  • Check this

    – Piyush
    Nov 21 '18 at 11:15











  • Possible duplicate of having a condition to fragment adding

    – Hossam Hassan
    Nov 21 '18 at 11:22














0












0








0








I have an issue please help me out. I am building an android application and I have successfully integrated Rewarded video ads to it.



I want to show a fragment or auto redirect to a specific fragment when the below condition is met:



@Override
public void onRewarded(RewardItem rewardItem) {
// I want to redirect the user to a particular fragment here.
}


So Please help me out, if there is any other way to achieve this then please let me know.










share|improve this question
















I have an issue please help me out. I am building an android application and I have successfully integrated Rewarded video ads to it.



I want to show a fragment or auto redirect to a specific fragment when the below condition is met:



@Override
public void onRewarded(RewardItem rewardItem) {
// I want to redirect the user to a particular fragment here.
}


So Please help me out, if there is any other way to achieve this then please let me know.







android android-activity fragment rewardedvideoad






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 11:19









Fantômas

32.6k156389




32.6k156389










asked Nov 21 '18 at 11:11









Syed NaveedSyed Naveed

398




398













  • So what is the issue ? Don't you aware of FragmentTransaction with FragmentManager?

    – Piyush
    Nov 21 '18 at 11:13











  • I am just starting out with android kindly help me.

    – Syed Naveed
    Nov 21 '18 at 11:14











  • Check this

    – Piyush
    Nov 21 '18 at 11:15











  • Possible duplicate of having a condition to fragment adding

    – Hossam Hassan
    Nov 21 '18 at 11:22



















  • So what is the issue ? Don't you aware of FragmentTransaction with FragmentManager?

    – Piyush
    Nov 21 '18 at 11:13











  • I am just starting out with android kindly help me.

    – Syed Naveed
    Nov 21 '18 at 11:14











  • Check this

    – Piyush
    Nov 21 '18 at 11:15











  • Possible duplicate of having a condition to fragment adding

    – Hossam Hassan
    Nov 21 '18 at 11:22

















So what is the issue ? Don't you aware of FragmentTransaction with FragmentManager?

– Piyush
Nov 21 '18 at 11:13





So what is the issue ? Don't you aware of FragmentTransaction with FragmentManager?

– Piyush
Nov 21 '18 at 11:13













I am just starting out with android kindly help me.

– Syed Naveed
Nov 21 '18 at 11:14





I am just starting out with android kindly help me.

– Syed Naveed
Nov 21 '18 at 11:14













Check this

– Piyush
Nov 21 '18 at 11:15





Check this

– Piyush
Nov 21 '18 at 11:15













Possible duplicate of having a condition to fragment adding

– Hossam Hassan
Nov 21 '18 at 11:22





Possible duplicate of having a condition to fragment adding

– Hossam Hassan
Nov 21 '18 at 11:22












2 Answers
2






active

oldest

votes


















1














Use Fragment Manager and Fragment Transaction Manager for this.



getFragmentManager().beginTransaction().replace(R.id.your_framelayout_id, new your_fragment()).commit();





share|improve this answer
























  • Thanks it helped!

    – Syed Naveed
    Nov 21 '18 at 15:34



















1














Write below code inside your onRewarded :



    android.support.v4.app.Fragment fragment = new FragmentA();
android.support.v4.app.FragmentManager fragmentManager = getActivity()
.getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction =
fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();


Here fragment_container is a FrameLayout defined inside your Activity on which you want to host your fragment.



I am mentioning a sample activity with a framelayout.



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Below is a fragment Container" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_height="wrap_content"
android:layout_width="match_content" />
</LinearLayout>





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410872%2floading-a-fragment-upon-a-specific-condition%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Use Fragment Manager and Fragment Transaction Manager for this.



    getFragmentManager().beginTransaction().replace(R.id.your_framelayout_id, new your_fragment()).commit();





    share|improve this answer
























    • Thanks it helped!

      – Syed Naveed
      Nov 21 '18 at 15:34
















    1














    Use Fragment Manager and Fragment Transaction Manager for this.



    getFragmentManager().beginTransaction().replace(R.id.your_framelayout_id, new your_fragment()).commit();





    share|improve this answer
























    • Thanks it helped!

      – Syed Naveed
      Nov 21 '18 at 15:34














    1












    1








    1







    Use Fragment Manager and Fragment Transaction Manager for this.



    getFragmentManager().beginTransaction().replace(R.id.your_framelayout_id, new your_fragment()).commit();





    share|improve this answer













    Use Fragment Manager and Fragment Transaction Manager for this.



    getFragmentManager().beginTransaction().replace(R.id.your_framelayout_id, new your_fragment()).commit();






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 21 '18 at 11:20









    Sam.Sam.

    412410




    412410













    • Thanks it helped!

      – Syed Naveed
      Nov 21 '18 at 15:34



















    • Thanks it helped!

      – Syed Naveed
      Nov 21 '18 at 15:34

















    Thanks it helped!

    – Syed Naveed
    Nov 21 '18 at 15:34





    Thanks it helped!

    – Syed Naveed
    Nov 21 '18 at 15:34













    1














    Write below code inside your onRewarded :



        android.support.v4.app.Fragment fragment = new FragmentA();
    android.support.v4.app.FragmentManager fragmentManager = getActivity()
    .getSupportFragmentManager();
    android.support.v4.app.FragmentTransaction fragmentTransaction =
    fragmentManager.beginTransaction();
    fragmentTransaction.replace(R.id.fragment_container, fragment);
    fragmentTransaction.commit();


    Here fragment_container is a FrameLayout defined inside your Activity on which you want to host your fragment.



    I am mentioning a sample activity with a framelayout.



    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Below is a fragment Container" />
    <FrameLayout
    android:id="@+id/fragment_container"
    android:layout_height="wrap_content"
    android:layout_width="match_content" />
    </LinearLayout>





    share|improve this answer




























      1














      Write below code inside your onRewarded :



          android.support.v4.app.Fragment fragment = new FragmentA();
      android.support.v4.app.FragmentManager fragmentManager = getActivity()
      .getSupportFragmentManager();
      android.support.v4.app.FragmentTransaction fragmentTransaction =
      fragmentManager.beginTransaction();
      fragmentTransaction.replace(R.id.fragment_container, fragment);
      fragmentTransaction.commit();


      Here fragment_container is a FrameLayout defined inside your Activity on which you want to host your fragment.



      I am mentioning a sample activity with a framelayout.



      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/main_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      tools:context=".MainActivity">

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Below is a fragment Container" />
      <FrameLayout
      android:id="@+id/fragment_container"
      android:layout_height="wrap_content"
      android:layout_width="match_content" />
      </LinearLayout>





      share|improve this answer


























        1












        1








        1







        Write below code inside your onRewarded :



            android.support.v4.app.Fragment fragment = new FragmentA();
        android.support.v4.app.FragmentManager fragmentManager = getActivity()
        .getSupportFragmentManager();
        android.support.v4.app.FragmentTransaction fragmentTransaction =
        fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fragment_container, fragment);
        fragmentTransaction.commit();


        Here fragment_container is a FrameLayout defined inside your Activity on which you want to host your fragment.



        I am mentioning a sample activity with a framelayout.



        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/main_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context=".MainActivity">

        <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Below is a fragment Container" />
        <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_height="wrap_content"
        android:layout_width="match_content" />
        </LinearLayout>





        share|improve this answer













        Write below code inside your onRewarded :



            android.support.v4.app.Fragment fragment = new FragmentA();
        android.support.v4.app.FragmentManager fragmentManager = getActivity()
        .getSupportFragmentManager();
        android.support.v4.app.FragmentTransaction fragmentTransaction =
        fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fragment_container, fragment);
        fragmentTransaction.commit();


        Here fragment_container is a FrameLayout defined inside your Activity on which you want to host your fragment.



        I am mentioning a sample activity with a framelayout.



        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/main_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context=".MainActivity">

        <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Below is a fragment Container" />
        <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_height="wrap_content"
        android:layout_width="match_content" />
        </LinearLayout>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 11:31









        Chandrani ChatterjeeChandrani Chatterjee

        705316




        705316






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410872%2floading-a-fragment-upon-a-specific-condition%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

            How to fix TextFormField cause rebuild widget in Flutter