### Android Activity Work Time Calculation Source: https://github.com/ellen2018/androidfaceinterview/blob/master/Android部分答案/Android部分-1 Activity答案.md Explains a conceptual approach to calculate the active working time of an Android Activity. This method leverages the Activity lifecycle by recording timestamps during the `onResume()` and `onPause()` callbacks, where `onResume()` marks the start and `onPause()` marks the end of an active period. ```APIDOC Activity starts working at onResume() and stops at onPause(). Record time 'a' when onResume() is called. Record time 'b' when onPause() is called. Work time = b - a. ``` -------------------------------- ### Java Custom Linked List: Get Size Source: https://github.com/ellen2018/androidfaceinterview/blob/master/算法与数据结构部分/算法与数据结构部分-3 链表.md This simple method returns the current number of elements stored in the custom singly linked list. It directly returns the 'size' field, implying the size is maintained during add/delete operations. ```Java public int size(){ return size; } ``` -------------------------------- ### Java Custom Linked List: Get Element by Index Source: https://github.com/ellen2018/androidfaceinterview/blob/master/算法与数据结构部分/算法与数据结构部分-3 链表.md This method retrieves the element at a specified zero-based index 'i' from the custom singly linked list. It performs bounds checking and iterates through the list until the target index is reached, returning the element's value. If the index is out of bounds, it prints an error and returns null. ```Java public E get(int i){ if(i<0||i>=size()){ System.out.println("越界异常"); return null; } Node dangQian = this.head.tail; int j=0; while(dangQian!=null){ if(j == i){ return dangQian.value; }else{ j++;dangQian =dangQian.tail; } } return null; } ``` -------------------------------- ### Android Activity Lifecycle Flow: A to B and Back Source: https://github.com/ellen2018/androidfaceinterview/blob/master/Android部分答案/Android部分-1 Activity答案.md Illustrates the precise sequence of Activity lifecycle callbacks when navigating from Activity A to Activity B, and subsequently returning from Activity B to Activity A using the back button. This demonstrates how Android manages Activity states during transitions. ```APIDOC From Activity A to Activity B: Activity A --> onPause() Activity B --> onCreate() Activity B --> onStart() Activity B --> onResume() Activity A --> onStop() Then in Activity B click back button: Activity B --> onPause() Activity A --> onRestart() Activity A --> onStart() Activity A --> onResume() Activity B --> onStop() Activity B --> onDestory() ``` -------------------------------- ### Android Activity Launch Mode: SingleInstance Behavior Source: https://github.com/ellen2018/androidfaceinterview/blob/master/Android部分答案/Android部分-1 Activity答案.md Explains the characteristics and behavior of the `SingleInstance` launch mode for Android Activities. This mode ensures that the Activity is a global singleton, residing in its own unique task stack, and any Activities launched from it will run in a different task. ```APIDOC SingleInstance Mode Characteristics: 1. Global Uniqueness: Only one instance of a SingleInstance Activity exists across the entire system. 2. Reuse: If an instance already exists when launched, its task is brought to the foreground, reusing the existing instance. 3. Exclusivity: A SingleInstance Activity occupies its own unique task stack. 4. Task Separation: Any Activity launched by a SingleInstance Activity will run in a different task (either a new one or an existing one). This mode is an enhanced version of singleTask, where the Activity is always the root of its own dedicated task. ``` -------------------------------- ### Java Custom Linked List: Demonstration of Operations Source: https://github.com/ellen2018/androidfaceinterview/blob/master/算法与数据结构部分/算法与数据结构部分-3 链表.md This 'main' method provides a comprehensive demonstration of the 'LinkedListCopy' class operations. It showcases adding elements (to end and at index), deleting elements, modifying elements, and searching for elements, printing the list state after each major operation. ```Java public static void main(String[] args){ LinkedListCopy linkedListCopy = new LinkedListCopy(); DieDaiQi dieDaiQi = linkedListCopy.dieDaiQi();//获取迭代器 //尾部增加 linkedListCopy.add("ss1"); linkedListCopy.add("ss2"); linkedListCopy.add("ss3"); linkedListCopy.add("ss4"); System.out.println("1*****尾部添加操作*****"); System.out.println("尾部添加操作后集合所有元素如下:"); while (dieDaiQi.moveToNext()){ System.out.println(dieDaiQi.next()); } System.out.println("此时集合元素个数:"+linkedListCopy.size()); System.out.println("1*****尾部添加操作*****\n"); //插入添加 linkedListCopy.add(0,"ss"); linkedListCopy.add(3,"ss2.5"); dieDaiQi.reSet();//重置迭代器 System.out.println("2*****插入添加操作*****"); System.out.println("插入添加操作后集合所有元素如下:"); while (dieDaiQi.moveToNext()){ System.out.println(dieDaiQi.next()); } System.out.println("此时集合元素个数:"+linkedListCopy.size()); System.out.println("2*****插入添加操作*****\n"); //删除 linkedListCopy.delete(3); dieDaiQi.reSet();//重置迭代器 System.out.println("3*****删除操作*****"); System.out.println("删除操作后集合所有元素如下:"); while (dieDaiQi.moveToNext()){ System.out.println(dieDaiQi.next()); } System.out.println("此时集合元素个数:"+linkedListCopy.size()); System.out.println("3*****删除操作*****\n"); //修改 linkedListCopy.gaiValue(0,"ss0"); dieDaiQi.reSet();//重置迭代器 System.out.println("4*****修改操作*****"); System.out.println("修改操作后集合所有元素如下:"); while (dieDaiQi.moveToNext()){ System.out.println(dieDaiQi.next()); } System.out.println("此时集合元素个数:"+linkedListCopy.size()); System.out.println("4*****修改操作*****\n"); //查询操作 int serachInt = linkedListCopy.serach("ss8"); if(serachInt==-1) { System.out.println("集合中不存在该元素!"); }else{ System.out.println("ss3存在的位置是:第" + (serachInt + 1) + "个"); } System.out.println(linkedListCopy.get(serachInt)); } ``` -------------------------------- ### Android Activity Management: Closing All or Specific Activities Source: https://github.com/ellen2018/androidfaceinterview/blob/master/Android部分答案/Android部分-1 Activity答案.md Describes a common pattern to manage and close all or specific Activities within an Android application. This involves maintaining a centralized list of Activity instances, adding them on `onCreate()` and removing them on `onDestroy()`, allowing for programmatic termination of Activities. ```APIDOC Pattern for Activity management: 1. Create a class (e.g., ActivityManager) with a static List collection. 2. In each Activity's onCreate() method, add the current Activity instance to the list. 3. In each Activity's onDestroy() method, remove the current Activity instance from the list. 4. To close all Activities: Iterate through the List and call finish() on each instance. 5. To close a specific Activity: Assign a unique tag to each Activity upon launch. Use this tag to find and finish the specific Activity instance from the list. ``` -------------------------------- ### Android Intent Flags for Activity Launch Modes Source: https://github.com/ellen2018/androidfaceinterview/blob/master/Android部分答案/Android部分-1 Activity答案.md Documents commonly used `Intent` flags that influence the launch behavior and task management of Android Activities. These flags provide fine-grained control over how Activities are placed in the task stack and how existing instances are handled during launch. ```APIDOC Common Intent Flags: 1. Intent.FLAG_ACTIVITY_NEW_TASK: Equivalent to specifying "singleTask" launch mode for the Activity. 2. Intent.FLAG_ACTIVITY_SINGLE_TOP: Equivalent to specifying "singleTop" launch mode for the Activity. 3. FLAG_ACTIVITY_CLEAR_TOP: - If used with "singleTask" launch mode: If the target Activity instance already exists, its onNewIntent() method will be called. - If the target Activity uses "standard" launch mode: All Activities on top of the target Activity in the stack will be popped, and a new instance of the target Activity will be created and placed at the top. 4. FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS: The new Activity will not be saved in the list of recently launched Activities. Equivalent to setting android:excludeFromRecents="true" in the manifest. ``` -------------------------------- ### Java Custom Linked List: Search Element Source: https://github.com/ellen2018/androidfaceinterview/blob/master/算法与数据结构部分/算法与数据结构部分-3 链表.md This method searches for a specified element 'e' within the custom singly linked list. It iterates through the list, comparing each node's value with the target element. If found, it returns the zero-based index; otherwise, it returns -1. ```Java public int serach(E e){ Node dangQian = this.head.tail; int j=0; while(dangQian != null){ if(dangQian.value.equals(e)){ return j; }else{ j++; dangQian = dangQian.tail; } } return -1; } ``` -------------------------------- ### Java Custom Linked List: Append Another List Source: https://github.com/ellen2018/androidfaceinterview/blob/master/算法与数据结构部分/算法与数据结构部分-3 链表.md This method appends all elements from another 'LinkedListCopy' instance to the end of the current list. It iterates through the nodes of the provided linked list and adds each element individually using the existing 'add' method. ```Java public void addAll(LinkedListCopy linkedListCopy){ Node dangQian = linkedListCopy.head.tail; while(dangQian != null){ this.add(dangQian.value); dangQian = dangQian.tail; } } ``` -------------------------------- ### Calculate Android View Nesting Level Source: https://github.com/ellen2018/androidfaceinterview/blob/master/Android部分答案/Android部分-16 View绘制机制.md This Java code snippet demonstrates a simple method to calculate the nesting depth of a given Android View within its parent hierarchy. It iteratively traverses up the parent chain, incrementing a counter until the root parent (which has no parent) is reached. This can be useful for debugging layout performance or understanding complex View structures. ```Java while (view.getParents() != null) { count++; view = view.getParents(); } ``` -------------------------------- ### Java Custom Linked List: Node Traversal and Update/Deletion Logic Source: https://github.com/ellen2018/androidfaceinterview/blob/master/算法与数据结构部分/算法与数据结构部分-3 链表.md This partial code snippet illustrates the internal loop logic for traversing a custom singly linked list. It checks if the current node's index 'j' matches a target index 'i'. If matched, it updates the node's value ('dangQian.value = e;') and breaks. Otherwise, it advances to the next node, updating 'j' and 'dangQian', and also storing the previous node in 'ago'. This pattern is common in methods like 'gaiValue' (modify) or 'delete'. ```Java if(j == i){ dangQian.value = e; break; }else{ j++; ago = dangQian; dangQian = dangQian.tail; } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.