【发布时间】:2018-03-29 11:05:29
【问题描述】:
活动需要更多时间才能启动。这是我的代码
Intent intent =new Intent(getActivity(), McallContactsActivity.class);
startActivity(intent);
我禁用了即时运行,然后尝试了。但启动活动需要更多时间。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mcall_contacts_activity);
toolbar = (android.support.v7.widget.Toolbar)
findViewById(R.id.toolbar);
recycleListFriend = (RecyclerView)
findViewById(R.id.recycleListFriend);
swipeRefreshLayout = (SwipeRefreshLayout)
findViewById(R.id.swipeRefreshLayout);
phoneContact = new PhoneContact();
if(toolbar != null) {
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Users");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
checkContactPermission();
setupAdapter();
phoneContactList = getContacts(McallContactsActivity.this);
DatabaseReference ref =
FirebaseDatabase.getInstance().getReference().child("user");
ref.addListenerForSingleValueEvent(
new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
dataSnapshot.getValue().keySet().iterator().next().toString();
String id = ((HashMap)
dataSnapshot.getValue()).keySet().iterator().next().toString();
collectPhoneNumbers((Map<String,Object>)
dataSnapshot.getValue());
}
@Override
public void onCancelled(DatabaseError databaseError) {
//handle databaseError
}
});
}
这是 MCallContactsActivity 的 onCreate 方法。此活动没有 onResume() 方法
【问题讨论】:
-
您的 oncreate() 方法需要更多时间。发布 McallContactsActivity 的 oncreate 方法
-
发布你的 McallContactActivity.class 的 onCreate 和 onResume 方法
-
打开一个活动所花费的时间主要是因为 Oncreate 中的代码在新活动上和旧活动的 Onpause 上。
-
避免在主线程中执行较长的操作。正因为如此,才需要更多时间来启动另一个 Activity。
-
@JyotiJK 我添加了 onCreate 方法。请你检查一下。谢谢
标签: android android-activity launch