问题描述
我从片段A到B.片段现在,当我点击回preSS,在片段A中的 onResume()
方法不叫。有谁知道什么可以为这个原因呢?
这是我曾尝试和 onResume
不叫:
公共类CurrencyFragment扩展android.support.v4.app.Fragment {
公共静态字符串的ImagePath = NULL;
静态的ArrayList< EquityDetails> catListDao =新的ArrayList< EquityDetails>();
静态的ArrayList< EquityDetails> catListDao1 =新的ArrayList< EquityDetails>();
静态诠释计数= 0;
静态布尔AB = FALSE;
ListView控件列表;
TextView的empty_text;
查看视图。
活动的行为;
AdvisorsAdapter适配器;
ImageView的进度;
CustomToast敬酒;
AnimatorSet设置;
私人布尔isViewShown = FALSE;公共静态的newInstance com.advisorymandi.CurrencyFragment(){
返回新com.advisorymandi.CurrencyFragment();
}@覆盖
公共无效setUserVisibleHint(布尔isVisibleToUser){
super.setUserVisibleHint(isVisibleToUser);
如果(isVisibleToUser){
isViewShown = TRUE;
如果(适配器!= NULL){
adapter.filter();
}
}其他{
isViewShown = FALSE;
}
}@覆盖
公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,捆绑savedInstanceState){
鉴于= inflater.inflate(R.layout.equity_activity,集装箱,FALSE);
ACT = this.getActivity();
Constants.check_fragment_visible = 1;
算上++;
返回视图。
}公共无效onActivityCreated(捆绑savedInstanceState1){
super.onActivityCreated(savedInstanceState1);
setHasOptionsMenu(真);
名单=(ListView控件)view.findViewById(R.id.list_equity);
empty_text =(TextView中)view.findViewById(R.id.empty);
进度=(ImageView的)view.findViewById(R.id.progressBar);
设定=(AnimatorSet)AnimatorInflater.loadAnimator(getActivity(),R.animator.fadein);
set.setTarget(进度);
progressBar.setVisibility(View.GONE);
如果(Utils.isNetworkAvailable(getActivity())){
如果(catListDao.size()大于0){
适配器=新AdvisorsAdapter(ACT,R.layout.custom_equity,catListDao,0);
list.setAdapter(适配器);
}其他{
如果(!isViewShown){
新FetchAllData(getActivity(),4).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
}其他{
敬酒=新CustomToast(getActivity(),没有互联网连接!);
}
}@覆盖
公共无效onResume(){
super.onResume();
如果(适配器!= NULL)adapter.notifyDataSetChanged();
Constants.check_fragment_visible = 1;
如果(Constants.check_reload){
如果(Utils.isNetworkAvailable(getActivity())){
如果(!isViewShown){
新FetchAllData(getActivity(),4).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}其他{
}
}其他{
敬酒=新CustomToast(getActivity(),没有互联网连接!);
}
}
}@覆盖
公共无效的onPause(){
super.onPause();}
}
}
片段生命周期总是与父活动的生命周期相关联,当你回到preSS片段弹出,因为它被添加到backstack但父活动是否完好是在前台所以没有调用onResume它已经在恢复状态,当你的父活动的简历上就是所谓的碎片onResume就会被调用。尝试preSS home键,回来的应用程序,看到的行为。
I am going from fragment A to fragment B. Now when I click on backpress, the onResume()
method in fragment A is not called. Does anyone know what can be the cause for this?
This is what I have tried and its onResume
is not called:
public class CurrencyFragment extends android.support.v4.app.Fragment {
public static String imagepath = null;
static ArrayList<EquityDetails> catListDao = new ArrayList<EquityDetails>();
static ArrayList<EquityDetails> catListDao1 = new ArrayList<EquityDetails>();
static int count = 0;
static boolean ab = false;
ListView list;
TextView empty_text;
View view;
Activity act;
AdvisorsAdapter adapter;
ImageView progressBar;
CustomToast toast;
AnimatorSet set;
private boolean isViewShown = false;
public static com.advisorymandi.CurrencyFragment newInstance() {
return new com.advisorymandi.CurrencyFragment();
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
isViewShown = true;
if (adapter != null) {
adapter.filter("");
}
} else {
isViewShown = false;
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.equity_activity, container, false);
act = this.getActivity();
Constants.check_fragment_visible = 1;
count++;
return view;
}
public void onActivityCreated(Bundle savedInstanceState1) {
super.onActivityCreated(savedInstanceState1);
setHasOptionsMenu(true);
list = (ListView) view.findViewById(R.id.list_equity);
empty_text = (TextView) view.findViewById(R.id.empty);
progressBar = (ImageView) view.findViewById(R.id.progressBar);
set = (AnimatorSet) AnimatorInflater.loadAnimator(getActivity(), R.animator.fadein);
set.setTarget(progressBar);
progressBar.setVisibility(View.GONE);
if (Utils.isNetworkAvailable(getActivity())) {
if (catListDao.size() > 0) {
adapter = new AdvisorsAdapter(act, R.layout.custom_equity, catListDao, 0);
list.setAdapter(adapter);
} else {
if (!isViewShown) {
new FetchAllData(getActivity(), 4).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
} else {
toast = new CustomToast(getActivity(), "There is no internet connection!");
}
}
@Override
public void onResume() {
super.onResume();
if (adapter != null) adapter.notifyDataSetChanged();
Constants.check_fragment_visible = 1;
if (Constants.check_reload) {
if (Utils.isNetworkAvailable(getActivity())) {
if (!isViewShown) {
new FetchAllData(getActivity(), 4).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
}
} else {
toast = new CustomToast(getActivity(), "There is no internet connection!");
}
}
}
@Override
public void onPause() {
super.onPause();
}
}
}
Fragment life cycle is always associated with parent activity's lifecycle when you backpress fragment pops up as it is added to backstack but parent activity is intact it is in foreground so there is no call to onResume it is already in resumed state,when your parent activity's on resume is called your fragments onResume will gets called. Try to press home button and come back to app and see behaviour.
这篇关于片段OnResume不叫背面preSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!