android 精华简书ITandroid开发文集

Android面试题(一)——Activity的生命周期和启动模

2016-07-03  本文已影响1880人  eagleRock

引言


面试题:


  1. Activity的生命周期

答:onCreate->onStart->onResume->Activity运行->新的Activity运行->onPause->onStop->onDestroy->Activity销毁


Activity生命周期的切换过程.png

答:四种启动模式,standard, singleTask, singleTop, singleInstance。

Fragment的生命周期.png

有四种方法

View listView = getActivity().findViewById(R.id.list);
ExampleFragment fragment = (ExampleFragment) getFragmentManager().findFragmentById(R.id.example_fragment);
    public static class FragmentA extends ListFragment {
        ...
        // Container Activity must implement this interface
        public interface OnArticleSelectedListener {
            public void onArticleSelected(Uri articleUri);
        }
        ...
        @Override
        public void onAttach(Activity activity) {
            super.onAttach(activity);
            try {
                mListener = (OnArticleSelectedListener) activity;
            } catch (ClassCastException e) {
                throw new ClassCastException(activity.toString() + " must implement OnArticleSelectedListener");
            }
        }
        @Override
        public void onListItemClick(ListView l, View v, int position, long id) {
            // Append the clicked item's row ID with the content provider Uri
            Uri noteUri = ContentUris.withAppendedId(ArticleColumns.CONTENT_URI, id);
            // Send the event and Uri to the host activity
            mListener.onArticleSelected(noteUri);
        }
    }
public void setArguments(Bundle args)
final pubilc Bundle getArguments()

知识点


  1. Activity典型情况下的生命周期分析

参考资料:


fagement官方文档
《Android开发艺术探究》
个人博客(https://yoxin.github.io/)

上一篇 下一篇

猜你喜欢

热点阅读