试经_2016

1、Fragment之间传值

        /**
         * Fragment 之间传值的方法
         * 1.通过Activity,实现前者的接口,然后向后者传值
         * 2.对于动态添加的Fragment,两者之间传值,可以通过Activity得到FragmentManager,
         * 然后通过findFragmentByTag,得到后者的引用
         */
        Fragment fragment1 = new Fragment();
        Fragment fragment2 = fragment1.getActivity().getFragmentManager().findFragmentByTag("TAG");
        fragment2.setText("Fragment1向Fragment2传值");

2、AutoCompleteTextView 的使用

//AutoCompleteTextView extends EditText implements //Filter.FilterListener
        AutoCompleteTextView actv = new AutoCompleteTextView(this);

        String [] names = {"老王","老李","老孙","老刘"};
        //arg2:显示每个条目的布局
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, names);
        actv.setAdapter(arrayAdapter);//设置数据适配器
        actv.setThreshold(1);//一个字符开始提示

        RelativeLayout view = (RelativeLayout)LayoutInflater.from(this).inflate(R.layout.activity_main, null);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.addView(actv,layoutParams);

        setContentView(view);

3、API版本对应系统版本号、support兼容包

API 4——1.6——Donut——v4(支持Fragment、ViewPager)
API 7——2.1—— Eclair——v7(支持ActionBar)
API 9——2.3—— Gingerbread
API 13——3.2——Honeycomb——v13(平板开发)
API 14-15——4.0-4.0.3——IceCreamSandwish
API 16-17-18——4.1-4.2-4.3——Jellybean
API 19——4.4——KitKat
API 21-22——5.0-5.1——Lollipop
API 23——6.0——Marshmallow

16-10-18

1、两个Activity切换的生命周期
08-25 05:02:47.783: INFO/System.out(339): MainActivity——->onPause()
08-25 05:02:47.843: INFO/System.out(339): Another——->onCreate()
08-25 05:02:47.853: INFO/System.out(339): Another——->onStart()
08-25 05:02:47.853: INFO/System.out(339): Another——->onResume()
08-25 05:02:48.253: INFO/System.out(339): MainActivity——->onStop()//—>Dialog样式不执行
调用finish()或按BACK键
08-25 05:10:48.053: INFO/System.out(366): Another——->onPause()
08-25 05:10:48.103: INFO/System.out(366): MainActivity——->onRestart()//—>Dialog样式不执行
08-25 05:10:48.103: INFO/System.out(366): MainActivity——->onStart()
08-25 05:10:48.103: INFO/System.out(366): MainActivity——->onResume()
08-25 05:10:48.423: INFO/System.out(366): Another——->onStop()
08-25 05:10:48.453: INFO/System.out(366): Another——->onDestroy()

2、线程和进程
程序是指令和数据的有序集合,其本身没有任何运行的含义,是一个静态的概念。

进程是程序在处理机上的一次执行过程,它是一个动态的概念。
进程是一个具有一定独立功能的程序,一个实体,每一个进程都有它自己的内存地址空间,
一个进程至少有一个线程,如果一个进程有多个线程,那么这个程序就称为多线程程序(
共享一个内存空间)。

线程实际上是在进程基础之上的进一步划分,一个进程启动之后,里面的若干程序又可以划分成
若干个线程。线程是进程中的一个执行路径,共享一个内存空间,线程之间可以自由切换,
并发执行,一个进程最少有一个线程(单线程程序)。

3、如何保持一个Service不被杀死
3-1 startForeground(id,notification);
3-2 onDestroy方法中启动自己
@Override
public void onDestroy() {
//启动当前Service
Intent intent = new Intent(this,MyService.class);
startService(intent);
super.onDestroy();
}

4、多继承带来的问题

//多实现,不会出现多继承时同名方法分不清的问题,只实现一个无所谓A或B的方法,因为都没有实现
interface A {
void method();

    void a();
}

interface B {
    void method();
}

static class C implements A, B {

    @Override
    public void method() {

    }

    @Override
    public void a() {

    }
}

//接口可以多继承
interface D extends A, B {
    void function();
}

static class E implements D {

    @Override
    public void function() {

    }

    @Override
    public void method() {

    }

    @Override
    public void a() {
        //Thread implements Runnable
        // class MyThread extends Thread implements Runnable{ run(){} }
    }
}

16-10-19

0、一张1280*720的图片的大小是怎样计算的?

答:像素数*一个像素所占的大小。
默认argb8888的情况下为:1280*720*4个字节。

1、问:Looper.myLooper()方法调用会返回什么?

答:需要看情况来分析。
若在主线程调用,那么返回一个Looper对象;子线程默认是没有Looper的,故会返回null。

2、问:那么怎么才能让他返回一个Looper呢?

答:需要调用Looper的prepare方法,会在子线程创建一个Looper。

3、问:此时的Looper和主线程的Looper是同一个对象吗?

答:不是的。

4、问:调用一个类的静态方法为什么不是返回同一个对象呢?他们是根据什么来区分的?

答:此并非单例。是根据线程来创建的,根据线程的id。

代码的验证

public class Main2Activity extends AppCompatActivity {

    private Looper mLooper;

    public static final String TAG = Main2Activity.class.getSimpleName();

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

        //主线程looper
        mLooper = Looper.myLooper();

        //Thread[main,5,main]-->Looper (main, tid 1) {1e6896a2}
        Log.d(TAG, "onCreate: " + Thread.currentThread() + "-->" + mLooper);

        new MyThread().start();
        new MyThreadCalledLooperPrepare().start();
    }

    class MyThread extends Thread {
        @Override
        public void run() {
            super.run();

            //子线程looper
            Looper looper = Looper.myLooper();

            //Thread[Thread-2230,5,main]-->null
            Log.d(TAG, "run: " + Thread.currentThread() + "-->" + looper);

            boolean b = mLooper == looper;

            //返回false
            Log.d(TAG, "run: " + b);
        }
    }

    class MyThreadCalledLooperPrepare extends Thread {
        @Override
        public void run() {
            super.run();

            //创建looper
            Looper.prepare();

            //子线程looper
            Looper looper = Looper.myLooper();

            //Thread[Thread-2231,5,main]-->Looper (Thread-2231, tid 2231) {33b9af33}
            Log.d(TAG, "run: " + Thread.currentThread() + "-->" + looper);

            boolean b = mLooper == looper;

            //false
            Log.d(TAG, "run: " + b);
        }
    }
}

下面是部分源码,可以看到,Looper.prepare()方法重新new了Looper对象。

/** Initialize the current thread as a looper.
      * This gives you a chance to create handlers that then reference
      * this looper, before actually starting the loop. Be sure to call
      * {@link #loop()} after calling this method, and end it by calling
      * {@link #quit()}.
      */
    public static void prepare() {
        prepare(true);
    }

    private static void prepare(boolean quitAllowed) {
        if (sThreadLocal.get() != null) {
            throw new RuntimeException("Only one Looper may be created per thread");
        }
        sThreadLocal.set(new Looper(quitAllowed));
    }

2016-10-21

1、Fresco的缓存机制

三级缓存。
dvm heap,native heap(ashmem(Anonymous Shared Memory),匿名共享内存),磁盘缓存(基于OKHttp的缓存);
1-1 为什么要使用native heap?两者的使用优先级?
Jvm的内存16M是有限的,需要来扩展;猜测是先dvm heap,后native。

2、OkHttp的实现机制

3、Java的内存回收机制

4、BroadcastReceiver实现机制

5、多线程编程熟练吗?

写过多线程下载,使用线程池管理的,使用缓存的线程池。
5-1 线程数量会无限增加吗?怎么控制的?
每个任务分为3个线程,下载任务上会做限制。
5-2 有做异常处理吗?比如开始后再次点击?没有。

6、MVP模式谈一下

7、项目

7-1、地址选择三级联动的效果怎么实现的?简单介绍一下?
7-1、项目的相关优化,如图片

8、你提高自己安卓技术的主要途径?有了解源码吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值