大佬教程收集整理的这篇文章主要介绍了android – 在奇怪的延迟后显示活动,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
只要单击菜单项或可单击视图,onClickListener就会创建一个新的Intent并启动指定的活动.到目前为止还可以.但是,在用户看到新活动之前,视图会被冻结一段时间(大约1秒).
那个时间可能是由onCreate里面的进展引起的,但是我通过System.currentTimeMillis()测量时间并在结尾处将其打印在logcat中.因此,它似乎只需要20-30毫秒,并且在用户看到活动之前很久就会打印日志.
这是我的代码:
public class ExampleActivity extends MyActivity { Mymodel mymodel; long startTime; protected void onCreate(Bundle savedInstanceStatE) { super.onCreate(savedInstanceStatE); startTime = System.currentTimeMillis(); setContentView(R.layout.activity_ders_programi); setToolbar(); mymodel = Controller.getMymodel(); if(mymodel == null) { //If we don't have the object prevIoUsly //this fills the object,takes some time mymodel = new Mymodel(this); //mymodel is observable and this activity is observer. //Whenever it's done,it notifies this activity } else //If we got the object prevIoUsly createCardViews(); Controller.setMymodel(mymodel); setParentActivity(); } //If Observable object notifies this activity,update() is called. @Override public void update(Observable observable,Object o) { createCardViews(); } //CreaTing a list of cardViews,this also takes some time private void createCardViews() { ArrayList<Card> cards = new ArrayList<Card>(); for(int i = 0; i < 5; i++) { MymodelCardModel card = new MymodelCardModel(this,i); card.init(); cards.add(card); } CardArrayAdapter mCardArrayAdapter = new CardArrayAdapter(this,cards); CardListView listView = (CardListView) findViewById(R.id.my_card_list_view); if (listView!=null) listView.setAdapter(mCardArrayAdapter); //I think here is the last point. //After this point there will be no significant process. long stopTime = System.currentTimeMillis(); Log.d("modelflow","card create takes: " + (stopTime - startTimE) + "ms"); }
那么我做错了什么?如果延迟是因为进度很大,那么为什么测得的时间似乎很少.假设进度导致延迟,为什么应用程序在显示活动后没有等待?以及如何避免这种情况?
以上是大佬教程为你收集整理的android – 在奇怪的延迟后显示活动全部内容,希望文章能够帮你解决android – 在奇怪的延迟后显示活动所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。