Android studio:执行停止未恢复的活动

时间:2016-04-28 13:41:10

标签: android android-studio android-lifecycle

当我执行我的应用程序(Android Studio 2.0 / RUN)时,我收到此错误消息(日志):

05-02 14:26:10.867 2225-2225/com.fmaupin.cogito E/ActivityThread: Performing stop of activity that is not resumed: {com.fmaupin.cogito/com.fmaupin.cogito.Main2Activity}
                                                                  java.lang.RuntimeException: Performing stop of activity that is not resumed: {com.fmaupin.cogito/com.fmaupin.cogito.Main2Activity}
                                                                      at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3344)
                                                                      at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3425)
                                                                      at android.app.ActivityThread.access$1100(ActivityThread.java:151)
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1332)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                      at android.os.Looper.loop(Looper.java:135)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                      at java.lang.reflect.Method.invoke(Method.java:372)
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)


                                                                  [ 05-02 14:26:10.894  2225: 2500 D/         ]
                                                                  HostConnection::get() New Host Connection established 0x7f44a4926b60, tid 2500
05-02 14:26:10.896 2225-2500/com.fmaupin.cogito I/OpenGLRenderer: Initialized EGL, version 1.4

我想了解问题是什么?

我读了很多关于这个问题的帖子,但我很难知道'源'的来源。

特别是因为这个问题仍未出现。

所以这是我活动的代码:

 public class Main2Activity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {
    ExpandableListView listView;

    // more efficient than HashMap for mapping integers to objects
    SparseArray<VersionN> groups = new SparseArray<VersionN>();

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

        createData();

        // liste des notes
        listView = (ExpandableListView) findViewById(R.id.notesList);

        // TEST : valeurs pour liste
        /*
        String[] values = new String[]{"Note 1 - c'est une première note sur un projet qui n'existe pas encore ! tout ça pour parler un peu",
                "Note 2",
                "Note 3",
                "Note 4",
                "Note 5",
                "Note 2",
                "Note 3",
                "Note 4",
                "Note 5",
                "Note 2",
                "Note 3",
                "Note 4",
                "Note 5",
                "Note 2",
                "Note 3",
                "Note 4",
                "Note 5",
                "Note 2",
                "Note 3",
                "Note 4",
                "Note 5",
                "Note 2",
                "Note 3",
                "Note 4",
                "Note 5",
        };

        // Define a new Adapter
        // First parameter - Context
        // Second parameter - Layout for the row
        // Third parameter - ID of the TextView to which the data is written
        // Forth - the Array of data

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1, values);

        // Assigner adapter à la liste
        listView.setAdapter(adapter);*/

        MyExpandableListAdapter adapter = new MyExpandableListAdapter(this,
                groups);
        listView.setAdapter(adapter);

        // ListView Item Click Listener
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                // ListView Clicked item index
                int itemPosition = position;

                // ListView Clicked item value
                String itemValue = (String) listView.getItemAtPosition(position);

                Log.i("List View Clicked", "**********");

                Toast.makeText(Main2Activity.this,
                        "List View Clicked : " + itemPosition + " " + itemValue, Toast.LENGTH_LONG)
                        .show();
            }

        });

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

        fab.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick (View view){
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
            }
        }
    );

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

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

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

    /**
     * initialize the list of notes
     *
     * @since 1.0
     */
    public void createData() {
        for (int j = 0; j < 5; j++) {
            VersionN group = new VersionN("Note " + j);

            for (int i = 0; i < 5; i++) {
                group.children.add("Version note " + i);
            }

            groups.append(j, group);
        }
    }

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main2, 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_settings) {
            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.nav_new_note) {
            // rédiger une note
        } else if (id == R.id.nav_list_notes) {
            // lister les notes
        } else if (id == R.id.nav_categories) {
            // gestion des catégories
        } else if (id == R.id.nav_projects) {
            // gestion des projets
        } else if (id == R.id.nav_settings) {
            // paramètres
        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
}

有什么想法吗?

提前谢谢

0 个答案:

没有答案