번들을 사용하여 활동에서 다른 단편으로 데이터를 전송할 수 있다는 것을 알고 있습니다. 몇 가지 연구를 해본 결과, Activity가 데이터를 전송해야하는 Fragment에 Fragment 트랜잭션을 커밋 할 때만 Bundle이 작동한다는 것을 알게되었습니다.커밋하지 않고 번들을 사용하여 활동에서 단편으로 데이터 전송 단편 트랜잭션
내 질문은 : 은 부분 트랜잭션을 커밋하지 않고 작업의 데이터를 다른 조각으로 보낼 수있는 방법이 있습니까?
나는 시나리오를 설명하는 이미지 첨부 :
여기
이 주요 활동 (User.java)입니다 : 여기
protected void onCreate(Bundle savedInstanceState) { ActionBar ab = getSupportActionBar(); ab.hide(); super.onCreate(savedInstanceState); setContentView(R.layout.activity_user); TextView txt = (TextView) findViewById(R.id.textView5); Intent intent = getIntent(); String Name = intent.getStringExtra("UserName"); txt.setText("Logged in as "+Name); Bundle bundle = new Bundle(); bundle.putString("message", Name); user_profile up = new user_profile(); //This is the Fragment where I want to send data(which is "Name") up.setArguments(bundle); user_home uh = new user_home(); //This is the Fragment that is added FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.add(R.id.fragment_container,uh); ft.commit(); }
제 2 차 활동 곳입니다 데이터를 보내려고합니다 ("user_profile.java"로 알려짐)
Bundle bundle2 = this.getArguments();
String N = bundle2.getString("message");
Toast.makeText(getContext(), N , Toast.LENGTH_SHORT).show();
번들을 사용하지 않고 액티비티와 프래그먼트간에 보낼 수있는 방법이 있습니까?
당신은'git' 태그를 제거 할 수 있습니다 –
사용 지역 방송을 사용할 수 있습니다. – Pavya
항상 된 SharedPreferences, 의도 또는 SQLite는 – AnoE