屏幕变暗后应用程序崩溃异常

时间:2013-08-10 09:34:42

标签: android

开始Android应用程序开发一直很棒 但是现在发生了一件新的事情!

用户未显示任何活动后,应用程序将被操作系统强制关闭

它以...着称的东西 现在这只发生在这个屏幕上,而不是主活动屏幕 我已将ListView用于此播放列表活动 现在 - 我想允许屏幕调暗,而不是禁用它!同时将应用程序保留在内存中! Plz任何人都可以告诉你如何

protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_playlist);
    // Show the Up button in the action bar.
    setupActionBar();
    ListView playlistView = (ListView)findViewById(R.string.playlistHolder);
    String[] STAR = { "*" };        
        Uri allsongsuri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
        String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
        @SuppressWarnings("deprecation")
        Cursor cursor = managedQuery(allsongsuri, STAR, selection, null, null);
        File musicstorage = new File("assets/music.xml");
     // Create the array list of to do items
            ArrayList<String> playItems = new ArrayList<String>();
            // Create the array adapter to bind the array to the listview
            ArrayAdapter<String> aa;
            aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,playItems);
            // Bind the array adapter to the listview.
            playlistView.setAdapter(aa);
        if (cursor != null)
        {
            if (cursor.moveToFirst())
            {
                do
                {
                    String song_name = cursor.getString(cursor
                            .getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
                    int song_id = cursor.getInt(cursor
                            .getColumnIndex(MediaStore.Audio.Media._ID));

                    String fullpath = cursor.getString(cursor
                            .getColumnIndex(MediaStore.Audio.Media.DATA));

                    String album_name = cursor.getString(cursor
                            .getColumnIndex(MediaStore.Audio.Media.ALBUM));
                    int album_id = cursor.getInt(cursor
                            .getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));

                    String artist_name = cursor.getString(cursor
                            .getColumnIndex(MediaStore.Audio.Media.ARTIST));
                    int artist_id = cursor.getInt(cursor
                            .getColumnIndex(MediaStore.Audio.Media.ARTIST_ID));
                    playItems.add(0, song_name);
                    aa.notifyDataSetChanged();
                } while (cursor.moveToNext());
            }
            cursor.close();
        }
}

1 个答案:

答案 0 :(得分:0)

相关问题here。此外,对于唤醒锁,请参阅http://developer.android.com/reference/android/os/PowerManager.html。特别是,根据您的需要,SCREEN_BRIGHT_WAKE_LOCK可能就足够了。至于app force关闭的原因,请发布一个Logcat 相关的代码部分。