Android face question [basics and details]

Source: Internet
Author: User
Tags eventbus

Thank @chuyao thrown these questions, usually write more business code, a lot of basic things become ambiguous, this naked word out to find a job did not go smoothly before, by the way to the Shanghai Android Development pit.
I have sorted out some of the answers, wrong or wrong place please point out, thank you.

1. What Windows components do activity build on? Incidentally involves the issue of the event delivery of the view.

Did not read the question, =. = Do not know whether to ask the activity UI structure, if it is possible to refer to this article.

For the view event delivery, you can Activity --> ViewGroup --> ...... --> Activity go from the * * U-shaped consumption structure to say.

2. Under what circumstances will the activity's Onnewinstent () method be executed? The activation mode of the activity is related.

When an instance of this activity already exists, and the startup mode at this time is the SingleTask SingleInstance same, it is also triggered when the instance is at the top of the stack and the startup mode is SingleTop onNewInstent() .

3. Activity a uses Startforresult to start activity b,b do nothing and return Onactivityresult callback in A,a will it execute?

The StartActivity () method, which is ultimately called startActivityForResult() methods. The default requestCode = -1 resultCode = RESULT_CANCELED = 0 , when you are requestCode != -1 , is onActivityResult() bound to be called.

4. Can the fragment not depend on activity existence? Brief analysis of fragment stack management.

fragment cannot exist independently , it must be embedded in the activity, and the life cycle of fragment is directly affected by the activity in which it resides.

//CreateNew Fragmentandtransactionfragment newfragment = new ExampleFragment (); Fragmenttransaction transaction = Getfragmentmanager (). BeginTransaction ();//Replace Whatever is in the Fragment_container view with this fragment,//and Span class= "Hljs-keyword" >add the transaction to the back stack transaction. replace (R.id.fragment_container, newFragment); Transaction.addtobackstack (null);//commit the transaction< Span class= "Hljs-keyword" >transaction. commit ();             

Transaction simply records the process of changing from one state to another, such as the process of replacing from Fragmenta to FRAGMENTB, when the transaction is added to the fallback stack through a function transaction.addtobackstack (null) , the state change process of the transaction is recorded, such as from FRAGMENTA->FRAGMENTB, when the user taps the phone fallback key, because the state of the transaction change process is saved, you can restore the state of the transaction, will be fragmentb- > Fragmenta.

Functions added to the fallback stack: transaction.addtobackstack (NULL);

Reference article: http://blog.csdn.net/u011026329/article/details/47903177

5. Is it possible to put an activity in the system's recent task list, independent of the host app task card?
我印象中是可以做到了,平时没用到,知道的同学请@我,谢谢!
6. For the same service, can it be bind after start?

Yes

Services are basically divided into two forms:
Start
When an application component (such as Activity) starts a service by calling StartService (), the service is in the "Started" state. Once started, the service can run indefinitely in the background, even if the component that started the service has been destroyed or not affected. A service that is started typically performs a single operation and does not return the results to the caller. For example, it may download or upload files over the network. When the operation is complete, the service stops running itself.
Binding
When an application component is bound to a service by calling Bindservice (), the service is in a "bound" state. The binding service provides a client-server interface that allows components to interact with the service, send requests, obtain results, and even take advantage of interprocess communication (IPC) to perform these operations across processes. The binding service runs only if it is bound to another application component. Multiple components can be bound to the service at the same time, but after all unbinding, the service is destroyed.

While this document is a separate overview of both services, your service can run in both ways, that is, it can either start the service (running indefinitely) or allow binding. The problem is simply whether you implement a set of callback methods: Onstartcommand () (allowing the component to start the service) and Onbind () (allowing the binding service).
From official documents

7. What are the derived classes of the service? What are the usage scenarios for these derived classes?

This question does not know what is the specific question, if you want to IntentService then refer to the Official document interpretation and use instructions:
Extended Intentservice Class
Because most start-up services do not have to handle multiple requests at the same time (in fact, this multithreaded scenario can be dangerous), implementing a service using the Intentservice class might be the best option.

Intentservice perform the following actions:

Intent。创建工作队列,用于将 Intent 逐一传递给 onHandleIntent() 实现,这样您就永远不必担心多线程问题。在处理完所有启动请求后停止服务,因此您永远不必调用 stopSelf()。提供 onBind() 的默认实现(返回 null)。提供 onStartCommand() 的默认实现,可将 Intent 依次发送到工作队列和 onHandleIntent() 实现。综上所述,您只需实现 onHandleIntent() 来完成客户端提供的工作即可。(不过,您还需要为服务提供小型构造函数。)

The following are examples of implementations of Intentservice:

PublicClassHellointentserviceExtendsIntentservice {/** * A constructor is required, and must call the Super Intentservice (String) * constructor with A name for the worker th Read. */PublicHellointentservice () {Super "Hellointentservice"); } /** * The Intentservice calls this method from the default worker thread with * the intent th At started the service. When this method returns, Intentservice * stops the service, as appropriate. */ @Override protected void Onhandleintent ( intent Intent) {//normally we would do some work here, like download a file. //for our sample, we just sleep for 5 seconds. try {thread.sleep (5000);} catch (interruptedexception e) {//Restore Interrupt status. thread.currentthread (). interrupt ();} }}

You only need a constructor and a onhandleintent () implementation.

If you decide to also override other callback methods (such as onCreate (), Onstartcommand (), or OnDestroy ()), be sure to call the superclass implementation so that Intentservice can gracefully handle the life cycle of the worker thread.

For example, Onstartcommand () must return the default implementation (that is, how to pass Intent to Onhandleintent ()):

@Overridepublic int onStartCommand(Intent intent, int flags, int startId) { Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show(); return super.onStartCommand(intent,flags,startId);}

Except for Onhandleintent (), the only way you do not need to call the superclass is Onbind () (this method is required only if the service allows binding).

8. What are the communication implementations between service and other components?
    1. Binder
    2. Broadcast
    3. See also how threads and processes communicate
9. In the View post (Runnable R) method, does r bring a new thread? Multithreading-related.

No, eventually the handler message is sent and executed on the UI thread.
The following are the source code and comments:

    /** * <p>causes The Runnable to being added to the message queue. * The runnable'll be run on the user interface thread.</p> * *@param action The Runnable that would be executed. *     *@return Returns True if the Runnable is successfully placed in to the * message queue.     Returns false on failure, usually because the * looper processing the message queue is exiting. *     *@see #postDelayed * @see #removeCallbacks *  /public boolean post(Runnable action) { final Attachinfo attachinfo = Mattachinfo; if (attachinfo! = null) { return attachInfo.mHandler.post (action);} //Postpone the runnable until we know on which thread it needs to run. //Assume that the runnable would be successfully placed after attach. Getrunqueue (). Post (action); return true;}             
10. What issues do I need to be aware of when using handler in non-UI threads?
new Thread(){        public void run(){ Looper.prepare();//给当前线程初始化Looper Toast.makeText(getApplicationContext(),"更新UI",0).show();//Toast初始化的时候会new Handler();无参构造默认获取当前线程的Looper,如果没有prepare过,则抛出题主描述的异常。上一句代码初始化过了,就不会出错。 Looper.loop();//这句执行,Toast排队show所依赖的Handler发出的消息就有人处理了,Toast就可以吐出来了。但是,这个Thread也阻塞这里了,因为loop()是个for (;;) ... } }.start();

Reference:
https://www.zhihu.com/question/51099935
https://www.zhihu.com/question/34652589

11. What are the important methods for customizing view, and what are their roles and order of execution?

In order:---- onMeasure() onLayout() onDraw() and others to expand it yourself.

12. How do I update an item on the ListView separately?
    1. Update the contents of the corresponding view
    2. To set a value by Viewholder
    3. Call once GetView () method (Google IO recommended)

Reference article http://blog.csdn.net/linglongxin24/article/details/53020164

13. Brief analysis of the loading processing of the large picture.

The understanding of bitmap, and then the compressed picture.

14. The designer only gave a set of 1280*800 UI map annotations, how to do other resolution size screen adaptation?
name pixel density range Picture Size
mdpi 120dp~160dp 48x48px
hdpi 160dp~240dp 72x72px
xhdpi 240dp~320dp 96x96px
xxhdpi 320dp~480dp 144x144px
xxxhdpi 480dp~640dp 192x192px

Take 720*1080 5 inches as an example:
(720^2 + 1080^2) prescribe =260
Put it in the xhdpi.

The same can be calculated in the same 293, or xhdpi.

15.6.0 the solution to the new authority mechanism of the system.

This one... There is nothing to say, really understand the very well, do not understand the words are a bit around.

? The open source framework you're proficient in, the problem is.

Writing a variety of mastery is actually possible, either true ox X, if not very bull X that at the end plus a proficient---- proficient in all kinds of beaten face .

What is the mechanism of Eventbus? What's the difference with handler?

EventBusThe event subscription bus is implemented using the observer pattern, which can be used in applications, between components, between threads, and because events can be any type of object, so it is easier and quicker to use them.
Handleris an Android messaging mechanism that focuses on inter-threading communication issues.

What is the mechanism of Rxjava?

Rxjava is a Java class library that uses the Java language to program in a responsive programming mindset . Reference ReactiveX .

What is the mechanism of butterknife?

Java Annotation processing Technology, when Java code is compiled into Java bytecode, has processed the annotations of @bind, @OnClick (Butterknife also supports many other annotations).

Annotation processing is a tool used in Javac to scan and parse Java annotations at compile time
Annotation processing is executed during the compile phase, and it is the principle of reading Java source Code, parsing annotations, and generating new Java code. The newly generated Java code is finally compiled into Java bytecode, and the annotation parser (Annotation Processor) cannot change the Java classes that are read in, such as the Java method cannot be added or deleted.
Reference: Butterknife Frame principle

is okhttp based on an HTTP connection or a socket connection?

Based on Http the.

20. Cite an ORM framework to say its merits and demerits.

I am familiar with the two GreenDao3 and AndroidActive , Greendao more conventional, the annotations are not many (I refer to the 3.0 version, the previous version in the survival of the entity is slightly troublesome. ), androidactive relatively annotated more, the final comprehensive performance on the Greendao row first without controversy. Hard to say the shortcomings of the words is Greendao volume slightly larger.

Android face question [basics and details]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.