I need your help regarding my application stream.
MainActivity (with Navigation Drawer)
ArticleActivity
Fragment C ( MainActivity) displays a list of elements ( ListView). Selecting an element leads to a fragment D (descriptor ArticleActivity), which represents this element in more detail.
Fragment D displays the Up button, which should allow the user to return to the previous screen (detailed view). The problem is that when you press the Up button, the previous activity is displayed, but not the previous activated fragment (the defaut ( A) fragment is displayed instead ).
My current code is:
public class FragmentC extends Fragment {
public static FragmentC newInstance() {
FragmentC fragment = new FragmentC();
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_courses, container, false);
...
setOnClickListener(new OnCardClickListener() {
@Override
public void onClick(Card card, View view) {
Intent i = new Intent(getActivity(), ArticleActivity.class);
i.putExtra("articleIndex", mArticle.getId());
startActivity(i);
}
});
...
return view;
}
}
public class ArticleActivity extends Activity {
private long mArticleIndex;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_course);
mArticleIndex = getIntent().getExtras().getLong("articleIndex", 0);
final ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
ArticleFragment fragment = ArticleFragment.newInstance(mArticleIndex);
getFragmentManager().beginTransaction().replace(R.id.container, fragment).commit();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent upIntent = new Intent(this, MainActivity.class);
upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(upIntent);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}
, , Intent. i.putExtra("displayFragment", FragmentD), MainActivity FragmentManager, . , .
, ?
?