Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8978721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:40:57+00:00 2026-06-15T19:40:57+00:00

MainActivity.java FragmentA fragmentA = null; FragmentB fragmentB = null; @Override protected void onCreate(Bundle savedInstanceState)

  • 0

MainActivity.java

FragmentA fragmentA = null;
FragmentB fragmentB = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

}

public void replaceFragment(Fragment newFragment){
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.right_container, newFragment);
    ft.addToBackStack(null);
    ft.commit();
}

public void removeFromActivity(Fragment oldFrag){
    FragmentManager manager = getFragmentManager();
    FragmentTransaction ft = manager.beginTransaction();
    manager.popBackStack();
    manager.executePendingTransactions();
    ft.remove(oldFrag);
    ft.commit();
}

FragmentA.java

public class FragmentA extends Fragment implements OnClickListener{

public View contentView;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    if(null == contentView){
        contentView = inflater.inflate(R.layout.fragment_a, null);
        EditText editTxt = (EditText) contentView.findViewById(R.id.right_frag_edit_txt);
        editTxt.setOnClickListener(this);
    }
     //--------------------------------------------------//
     //Here If I am printing
     EditText editTxt = (EditText) contentView.findViewById(R.id.right_frag_edit_txt);
     System.out.println(editTxt.getText()); //Output -- Now Button has Clicked --New value as expected
    return contentView;
}

public void setValues(String newVal){
    EditText editTxt = (EditText) contentView.findViewById(R.id.right_frag_edit_txt);
    editTxt.setText(newVal);
}

@Override
public void onClick(View v) {
    FragmentB newFrag = new FragmentB();
    ((MainActivity)getActivity()).fragmentB = newFrag;
    ((MainActivity)getActivity()).replaceFragment(newFrag);
}
}

FragmentB.java

public class ReplacedFragment extends Fragment implements OnItemClickListener{

public View contentView;

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    if(null == contentView){
        contentView = inflater.inflate(R.layout.fragment_b, null);
    }
    return contentView;
}

@Override
public void onClick(View v) {
    FragmentA previousFrag = ((MainActivity)getActivity()).fragmentA;
    previousFrag.setValues("Now Button has Clicked");
    ((MainActivity)getActivity()).removeFromActivity(this);
}
}

From fragmentB when I am clicking a button “Back”, I am simply removing this fragment from back stack. As a result FragmentB resumes back. But the edittext value is not updating with new value.

What should I do to update some view of FragmentA when it is resuming back. Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:40:58+00:00Added an answer on June 15, 2026 at 7:40 pm

    Finally I found a solution, but I don’t know whether its an efficient solution or not. but still I am sharing it.

    While starting FragmentB from fragmentA, it will call onPause() of FragmentA where I have set a flag to true. And when FragmentB is removed from FragmentTransaction, it will call to onResume() of FragmentA where I am checking the flag value and updating the FragmentA.

    I think this is a better solution, instead of calling lifecycle method onPause() explicitly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A simple android Hello World: MainActivity.java: package com.amaker.ch02.app; import android.app.Activity; import android.os.Bundle; import android.widget.TextView;
I have an activity ( MainActivity.java ) in which content view is like this
I have 2 tabs, named : Tab1, Tab2 class MainActivity extends TabActivity. MainActivity.java public
I called my main activity Main, and Eclipse created Main.java and res/layout/main.xml for the
I am developing an android app using phonegap (cordova-2.1.0). My MainActivity.java code is as
I have MainActivity.java as my first Fragment and the another Fragment being Fragment.java having
on MainActivity.java I have host.addTab(host.newTabSpec(Map) .setIndicator(Map, getResources().getDrawable(R.drawable.icon_user)) .setContent(new Intent(this, Map.class))); On Map.Java public class
I am using service in my program where i have MainActivity.java and MyService.java in
This is a location based app.The MainActivity.java is the first file to get executed,But
In my Android project I just have one Activity - MainActivity.java. I added another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.