android development Miscellany (a)

 

   

- Activity in the use of Tablayout + ViewPager filling Fragment of

   Fragment and with less content in different situations, you can create different Fragment respectively, with ViewPager use no problem.

   However, if the number of Fragment variable, and the contents of the same format, it is necessary to use the same Fragment, multiplexed inside layout. But this time will be a problem, good load data, fill in

  After the list ViewPager and TabLayout, the effect on the interface only Tab is normal, when you click Tab, Fragment is not corresponding, there will be gaps and misalignment of the situation;

   - problem causes:

    When using ViewPager, to use FragmentPagerAdapter, which FragmentManager to pass a parameter, in Activity, we can easily pass only

   getSupportFragmentManager (), (since now use Fragment v4 packet, app packet fragment and corresponding getFragmentManger () has been abandoned),

   The existence of FragmentManager problem is, he will automatically reuse Fragment, avoid repeatedly creating, destroying, but this will lead us to a different Tab corresponding Fragment,

   It has not been successfully created, but constantly being created behind cover.

    Because ViewPager preloaded default is 3 Fragment, so when you click on the fourth Tab, it will not load a blank but not necessarily correct Fragment.

   -solution:

    (1) the first case, Activity using ViewPager

      Do not use ViewPager, only the classification TabLayout save the title, ViewPager position just put a Fragment, then TabLayout monitor settings,

      tabLayout.addOnSelectedListener (), when selected, Tab acquire position information, and then load the data into or replaced by a unique location information Fragment.

    

 

    (2) Another case is a ViewPager Fragment nested, in common with the outer Fragment BottomNavigationView, forming two layers selected from the multiple interface

      When set to a ViewPager PagerAdapter, may be used getChildFragmentManager () Fragment in the outer layer, the inner layer does not make such a Manger multiplexed Fragment

      Also questions blank and will not appear misplaced. (Never used)

 

- the top toolbar immersed in the status bar, covered the top of the screen

  

  To achieve the effect, add a sentence as long as the subject of correspondence in the styles.xml

 

- do not automatically get the focus when EditText opening the interface, automatically lose focus when clicking outside

   If not set, then, EditText will automatically get the focus when entering the interface, click the interface in the other position, the soft keyboard is not recovered, worst experience

    (1), the first focus is not set to automatically obtain, add focusableInTouchMode = "true" in the parent layout EditText

  

    (2) Click outside seasonal EditText loses focus, to recover the soft keyboard

      Approach is to monitor the click event, if the point in EditText outside, let it loses focus

  

      Such experience would be better.

 

- guess interface pops up when unlock the lock screen

    Sometimes after a fingerprint to unlock, Jingdong interface will pop up, click on the back button to return to the main interface, then click interface when Jingdong, or appear before, but click on the rollback again, it will exit Jingdong,

    Back to the main screen, once again point Jingdong, will start the normal process.

     Combined with the contents of the first chapter of "Android development of artistic exploration," Jingdong guess is that the use of other processes running start their own Activity,

    这时Activity运行在其他进程的任务栈中,当第一次点击京东时,该Activity发现自己本应属于的任务栈启动了,就移动到京东进程的任务栈,

    再次退回主界面,Actvity和任务栈被销毁。

    (近期没使用京东,有机会再研究)

  

--    Activity的启动模式

    - standard ,标准模式,点一下启动一个,无脑入栈

    - singleTop   栈顶复用, 

      如果当前不在栈顶,就创建新实例入栈,和standard表现一致。 

      如果当前活动在栈顶,就不重复创建而调用 onNewIntent()。

      (示例为将 BetaActivity设为 singleTop ,反复启动二三活动 以及重复启动BetaActivity时, 用adb shell 命令看到的栈信息)

     BetaActivity不在栈顶的情况:会和ThirdActivity交替反复创建实例

    BetaActivity在栈顶的情况: 不再创建新实例,栈中活动数不变

 

    -  singleTask  栈内复用

    如果栈内有需要的活动,就将其显示出来。而要显示,就要把在其之上的活动全部出栈。

    需要注意的是,如果两个任务栈分别在前台和后台,当启动后台的活动时,后台任务栈会移动到前台栈之前,成为前台任务栈,而栈中的弹出关系,也遵循

    前面说过的规则。

    -  singleInstance 单例模式

    单独在一个任务栈内,栈中只能有自己一个实例。(实际上也符合singleTask的特征)

    

Guess you like

Origin www.cnblogs.com/xfdmyghdx/p/11216991.html