Reputation: 4242
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 -
Skipped 91 frames! 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);
}
}
};
}
Upvotes: 0
Views: 5443
Reputation: 29
I think this can help you. I think Use uiThread will clear this warning. 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();
Upvotes: 2