Android应用程式不断显示「应用程式没有回应」错误

时间:2019-07-05 11:51:15

标签: android performance androidx

我最近迁移到 androidX 来开发我的应用程序。但是,当我在设备上运行该应用程序时,它始终显示“应用程序无响应”错误消息。我刚刚添加了抽屉活动和两个片段。当我运行该应用程序时,它会持续滞后。即使抽屉滑动需要花费很多时间,而且当我单击片段上的按钮时,它的click事件也会在很长时间后响应。不知道到底出了什么问题。使用支持库的项目虽然包含两个以上的片段,但它们并不落后。感谢您的帮助。

我的抽屉活动代码

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;
}
}

**日志中没有错误。

我还在第一个片段中添加了mapview,第二个片段中包含了calenderview。如果需要的话,我将在此处发布整个代码,但它只包含位置服务和一些在单击按钮时触发的api调用。

日志显示此 E / MultiWindowProxy:getServiceInstance失败!我正在搜索它。

1 个答案:

答案 0 :(得分:0)

要修复 E / MultiWindowProxy:getServiceInstance失败!错误,我认为您需要在清单文件中使用<uses-library android:required="false" android:name="com.sec.android.app.multiwindow"> </uses-library>

至于该应用程序没有响应错误,我认为您的问题可能是您在没有必要权限的情况下请求用户信息。否则,我将尝试在调试中运行该应用程序,并查看您的代码在执行的哪一行(或代码部分)无法执行。