应用程序在Nexus 6 Android marshmallow上工作非常慢Skipped" n"帧

时间:2016-04-14 11:27:05

标签: android android-6.0-marshmallow

我需要帮助解决一个我真正不明白的问题。

我正在处理我使用真实设备进行调试的应用。我有两个,第一个是具有低资源(Android 5.0.2)的摩托罗拉,这有助于我捕获更多错误;在这一个应用程序扼杀完美地工作。第二个设备是 Nexus 6(Android 6.0.1),其中应用非常糟糕,它变得非常慢(即使没有做任何事情,例如打开菜单)它向我显示了这样一条消息:跳过33帧!应用程序可能在其主线程上做了太多工作。

我必须使用asynk任务,并且我使用主线程来减少我能做的事情。正如我之前所说,它显示了" skkiped框架"即使我只打开一个菜单(这意味着我没有下载或做一些奇怪的事情)的消息。该应用程序永远不会崩溃,但速度极慢。

我已在SDK管理器上安装了所有内容。

我将向您解释一个示例,其中我的应用程序变慢并向您显示代码。在我的主要活动中,我有一个带有NavigationView的工具栏,所以当我点击"菜单按钮"打开它,打开它需要3秒钟。

MainActivity代码:

public class MainActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener, View.OnClickListener {

private Toolbar toolbar;
//private FloatingActionButton fab;
private DrawerLayout drawer;
private ActionBarDrawerToggle toggle;
private NavigationView navigationView;
private FragmentManager fragmentManager;
private FragmentTransaction fragmentTransaction;
private static final String TAG = "MainActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    initMaterialDesign();

    if (savedInstanceState == null){
        showFragment(Constants.FRAGMENT_MENU);
        navigationView.getMenu().getItem(0).setChecked(true);
        getSupportActionBar().setTitle("Menú");
    } else{

    }


}

private void initMaterialDesign(){
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    /*fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(this);*/

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);

    drawer.addDrawerListener(toggle);

    toggle.syncState();

    navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

//@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_menu) {
        getSupportActionBar().setTitle("Menú");
        showFragment(Constants.FRAGMENT_VALORES);
    } /*else if (id == R.id.nav_gallery) {
        item.setChecked(true);
    } */else if (id == R.id.nav_contactanos) {
        contactanos();
    } /*else if (id == R.id.nav_manage) {
        item.setChecked(true);
    }*/else if (id == R.id.nav_logut) {
        logOut();
    }
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

@Override
public void onClick(View v) {
    switch (v.getId()){
       /* case R.id.fab:
            Snackbar.make(v, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
            break;*/

    }
}

private void showFragment(int fragment){
    fragmentManager = getSupportFragmentManager();
    fragmentTransaction = fragmentManager.beginTransaction();
    switch (fragment){
        /*case Constants.FRAGMENT_VALORES:
            ValoresFragment valoresFragment = new ValoresFragment();
            fragmentTransaction.replace(R.id.main_act_contenedorFragments, valoresFragment);
            break;
        case Constants.FRAGMENT_NOTICIAS:
            break;
        case Constants.FRAGMENT_WATCHLIST:
            break;
        case Constants.FRAGMENT_PORTFOLIO:
            break;*/
        case Constants.FRAGMENT_MENU:
            MenuFragment menuFragment = new MenuFragment();
            fragmentTransaction.replace(R.id.main_act_contenedorFragments, menuFragment);
            break;
    }
    fragmentTransaction.commit();
}

private void logOut(){
    new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
            .setTitleText(getString(R.string.nav_logout))
            .setContentText(getString(R.string.seguro_logout))
            .showCancelButton(true)
            .setConfirmText(getString(R.string.aceptar))
            .setCancelText(getString(R.string.cancelar))
            .setCancelClickListener(new SweetAlertDialog.OnSweetClickListener() {
                @Override
                public void onClick(SweetAlertDialog sDialog) {
                    sDialog.dismiss();
                }
            })
            .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
                @Override
                public void onClick(SweetAlertDialog sDialog) {
                    sDialog.dismissWithAnimation();
                    borrarSPUser();
                    irLoginAct();
                    MainActivity.this.finish();

                }
            })
            .show();
}

private void borrarSPUser(){
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString("usuario", "");
    editor.putString("pass", "");
    editor.commit();
}

private void irLoginAct(){
    Intent intentRegistroActivity = new Intent(MainActivity.this, LoginActivity.class);
    startActivity(intentRegistroActivity);
}

private void contactanos(){

    final Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"));
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"comunica@gmail.com"});
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My App");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Cuéntanos lo que quieras sobre la bolsa");

    startActivity(Intent.createChooser(emailIntent, "Elegir cliente:"));
}
}

我知道这段代码不会帮助你获得答案,但我只想告诉你我没有做任何奇怪的事。

这是logcat:

    04-14 12:34:28.596 8419-8419/? I/art: Late-enabling -Xcheck:jni
    04-14 12:34:28.646 8419-8419/? W/System: ClassLoader referenced unknown path: /data/app/com.myapp-1/lib/arm
    04-14 12:34:28.677 8419-8419/? V/Aplicacion: initParse: Parse iniciado
    04-14 12:34:28.725 8419-8425/? I/art: Debugger is no longer active
    04-14 12:34:28.764 8419-8445/? D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
    04-14 12:34:28.815 8419-8445/? I/Adreno: QUALCOMM build                   : 52af4d2, I8366cd0437
                                             Build Date                       : 10/20/15
                                             OpenGL ES Shader Compiler Version: XE031.05.13.02
                                             Local Branch                     : M14
                                             Remote Branch                    : 
                                             Remote Branch                    : 
                                             Reconstruct Branch               : 
    04-14 12:34:28.819 8419-8445/? I/OpenGLRenderer: Initialized EGL, version 1.4
    04-14 12:34:31.008 8419-8419/com.myapp V/LoadingActivity: DescargarAcciones >> Lista Acciones guardada en Application class
    04-14 12:34:32.369 8419-8419/com.myapp V/LoadingActivity: getLastUpdate >> UPDATE
    04-14 12:34:33.216 8419-8425/com.myapp W/art: Suspending all threads took: 28.414ms
    04-14 12:34:33.663 8419-8419/com.myapp V/LoadingActivity: descargarHistorial >> historialIbex35 descargado y guardado
    04-14 12:34:33.664 8419-8419/com.myapp V/LoadingActivity: modificarUltimoUpdate - Void done >> update realizado
    04-14 12:34:34.000 8419-8419/com.myapp V/LoadingActivity: descargarRanking >> EXITO
    04-14 12:34:34.000 8419-8419/com.myapp V/LoadingActivity: parsearRanking >> listaRanking guardada correctamente
    04-14 12:34:34.211 8419-8425/com.myapp W/art: Suspending all threads took: 22.491ms
    04-14 12:34:34.915 8419-8419/com.myapp I/Choreographer: Skipped 32 frames!  The application may be doing too much work on its main thread.
    04-14 12:48:33.438 8419-8419/com.myapp I/Choreographer: Skipped 35 frames!  The application may be doing too much work on its main thread.
    04-14 12:48:42.979 8419-8419/com.myapp I/Choreographer: Skipped 32 frames!  The application may be doing too much work on its main thread.
    04-14 12:48:43.537 8419-8419/com.myapp I/Choreographer: Skipped 33 frames!  The application may be doing too much work on its main thread.

我真的不知道发生了什么。我想要记住,这在低资源设备上完美运行,并且它在好的设备上运行得非常慢。我已经上网了,但我没有找到任何东西。如果有人能给我一个提示,那将非常感激。提前完成。

1 个答案:

答案 0 :(得分:3)

经过长时间寻找我的问题的答案,我没有找到任何解决方法,但我得到了一些帮助我得到答案的一些提示。

我找到了一些答案,这些答案表明问题可能是由资源(drawables)造成的,但我确信我的drawables已针对我的应用程序的每个屏幕密度进行了适当的调整。

问题在于我错误地认为Nexus 6(以及不是平板电脑的每台设备)的屏幕密度都是从ldpi到xxhdpi。在这种情况下,Nexus 6的屏幕密度为DisplayMetrics.DENSITY_560,因此我们可以找到here,它位于DENSITY_XXHIGH(480 dpi)和DENSITY_XXXHIGH之间的屏幕的

中间密度(640 dpi)。
所以文档说:
这不是应用程序应该定位的密度,而是依靠系统为它们扩展DENSITY_XXXHIGH资产。

总之,问题是在试图为Nexus 6屏幕密度进行缩放时引起的,因此应用程序进入无限循环。

最后我创建了xxxhdpi-drawable文件夹,问题解决了。

很难为我检测到这一点,因为我对整个应用程序都有相同的背景,所以自从我启动应用程序后,每次活动都出错了,没有没有背景或不同背景的活动可以正常工作。

我希望这可以帮助那些遇到同样问题的人。