I recently migrated to androidX for developing my app.But when I run the app on my device ,it always shows "App isn't responding" error message. I have just added the drawer activity and two fragments to it. When I run the app, it lags continuously.Even the sliding of drawer takes much time and also when I click the button on the fragment ,it's click event is responding after long time.Don't know what exactly is going wrong.My other projects, which use support library, aren't lagging although they contain much more than just 2 fragments.Thanks for any help.
My drawer activity code
public class DrawerActivity extends MAWBaseActivity implements NavigationView.OnNavigationItemSelectedListener {
DrawerLayout drawer;
NavigationView navigationView;
ActionBarDrawerToggle toggle;
FrameLayout logNWorkContainer;
ImageView ivUserImage;
TextView tvUserName;
TextView tvUserDesignation;
TextView tvUserCode;
View navHeader;
LinearLayout activityProgressLayout;
ProgressBar activityProgress;
/**
* Intent
*
* @param context calling activity context
*/
public static void show(Context context) {
Intent intent = new Intent(context, DrawerActivity.class);
context.startActivity(intent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drawer);
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
logNWorkContainer = findViewById(R.id.logNWorkContainer);
drawer = findViewById(R.id.drawer_layout);
navigationView = findViewById(R.id.nav_view);
activityProgressLayout = findViewById(R.id.activityProgressLayout);
activityProgress = findViewById(R.id.activityProgress);
toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
navigationView.setNavigationItemSelectedListener(this);
// Navigation view header
navHeader = navigationView.getHeaderView(0);
ivUserImage = navHeader.findViewById(R.id.ivUserImage);
tvUserName = navHeader.findViewById(R.id.tvName);
tvUserDesignation = navHeader.findViewById(R.id.tvUserDesignation);
tvUserCode = navHeader.findViewById(R.id.tvUserCode);
UserData userData = UserCache.user().getUserData();
if (userData == null) {
Login.show(this);
finish();
}
if (userData != null) {
// getNotificationAPICall(userData);
String name = ifNullReplace(userData.getFirstName(), EMPTY) + " " + ifNullReplace(userData
.getLastName(), EMPTY);
tvUserName.setText(name);
if (userData.getCode() == null) {
tvUserCode.setVisibility(View.GONE);
} else {
tvUserCode.setText("Emp No :- " + userData.getCode());
}
if (userData.getUserDesignation() == null || userData.getUserDesignation().equalsIgnoreCase(EMPTY)) {
tvUserDesignation.setVisibility(View.GONE);
} else {
tvUserDesignation.setVisibility(View.VISIBLE);
tvUserDesignation.setText(ifNullReplace(userData.getUserDesignation(), EMPTY));
}
ivUserImage.setImageResource(R.drawable.ic_user_new);
String url = UrlConstant.GET_THUMB_BY_NAME + userData.getPhoto() + UrlConstant.SIZE_100 + UrlConstant.IMAGE_USER;
UIUtils.loadRoundImage(url, ivUserImage, R.drawable.ic_profile_small);
}
HomeFragment homeFragment = new HomeFragment();
beginFragmentTransaction(homeFragment, "Home");
}
/**
* Begin fragment transaction
*
* @param fragment fragment
* @param name name of menu
*/
public void beginFragmentTransaction(Fragment fragment, String name) {
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
}
getSupportActionBar().setTitle(name);
// Insert the fragment by replacing any existing fragment
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.logNWorkContainer, fragment).commit();
}
/**
* Get activity progress
*
* @return progressbar
*/
public ProgressBar getActivityProgress() {
return activityProgress;
}
@Override
public void onBackPressed() {
drawer = findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
Dialogs.getInstance().showExitDialog(DrawerActivity.this);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_notifications) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.menu_home) {
HomeFragment homeFragment = new HomeFragment();
beginFragmentTransaction(homeFragment, getString(R.string.menu_home_label));
return true;
} else if (id == R.id.menu_calender) {
CalenderFragment calenderFragment = new CalenderFragment();
beginFragmentTransaction(calenderFragment, getString(R.string.menu_company_calender_label));
return true;
}
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
** There are no errors in logs.
Also I have added mapview in first fragment and the second fragment contains calenderview.If needed I'll post the whole code here, but it just contains location service and some api calls that are triggered on button click.
The logs show this E/MultiWindowProxy: getServiceInstance failed! I'm searching for it.