[英]Application may be doing too much work on its main thread
I am very new for android and in my app,I have added fragment on activity when I tapped on button which is added on my fragment class I am getting warning on my log cat like below - 我对android来说是一个非常新的人,在我的应用程序中,我点击了片段类上添加的按钮后,就在活动中添加了片段,我在日志猫上收到如下警告:
Skipped 91 frames! 跳过91帧! The application may be doing too much work on its main thread. 该应用程序可能在其主线程上做太多工作。
please help me how can I solve this? 请帮我如何解决这个问题?
public class BatchDetailsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.batchdetails_main_layout);
//Intializing Fragments:-
Intent i = getIntent();
String fragment = i.getStringExtra("DetailsFragment_Key");
intializingFragments(fragment);
}
private void intializingFragments(String fragmentType){
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
if (fragmentType.equals("BatchDetailsFragment")) {
BatchDetails_Fragment fragment = new BatchDetails_Fragment();
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.commit();
}else if(fragmentType.equals("RaisePoDetailsFragment")){
Rasing_po_Fragment fragment = new Rasing_po_Fragment();
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.commit();
}
}
}
public class Rasing_po_Fragment extends Fragment implements AdapterView.OnItemSelectedListener {
View view;
Button select
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_raisepo_layout,container,false);
select.setOnClickListener(buttonClickEvents());
return view;
}
//Select and Cancel button implementation:-
private View.OnClickListener buttonClickEvents(){
return new View.OnClickListener() {
@Override
public void onClick(View v) {
int getId = v.getId();
if (getId == R.id.selectbuttonid){
Intent i = new Intent(getActivity(), PoFinalizaion.class);
getActivity().startActivity(i);
}
}
};
}
I think this can help you. 我认为这可以为您提供帮助。 I think Use uiThread will clear this warning. 我认为使用uiThread将清除此警告。 In Your Activity, use this code: 在您的活动中,使用以下代码:
new Thread(new Runnable() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
//your code or your request that you want to run on uiThread
}
});
}
}).start();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.