Android - Activity open on the emulator but not in device

夙愿已清 提交于 2019-12-13 04:31:17

问题


I develop a little project in android and run ok on the emulator, but in my device only the first Activity is shown. here's the cod of my Second Activity...:

public class SecondActivity extends ListActivity {
//database Source
private DataSource datasource;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

datasource = new DataSource(this);
datasource.open();

File sdcard2 =  Environment.getExternalStorageDirectory();

for(File f: sdcard2.listFiles()){
            if(f.isFile()) {

             if(f.getName().endsWith("MP3")|| f.getName().endsWith("mp3")){
                // Comment comment = null;

                  MediaMetadataRetriever mmr = new MediaMetadataRetriever();
                  mmr.setDataSource(Environment.getExternalStorageDirectory().getPath()+'/'+f.getName());
                  String mus = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
                  String art = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
                  datasource.InsereMusica(art,mus);


                                    }

                        }
            }
//Get the itens for the ListView
List<String> values = datasource.getAll();

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

                registerForContextMenu(getListView());

}

The XML :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

 <ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="@string/hello" />

</LinearLayout>

The Manifest:

   <uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="10" />
  <uses-permission android:name="android.permission.INTERNET"></uses-permission>
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <activity android:name="Inicio" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
        <activity
        android:name="SecondActivity"
        android:label="@string/app_name"
        android:theme="@style/Theme.Blundell.Light" >




    </activity>

So, I run normally on emulator 2.3.3 but don't works on my device android 2.3.4

Have something wrong ?

Thank you.


回答1:


Are you using same layout for both activities?, I think you are using same layout as this line generally shows first activity layout : setContentView(R.layout.main);



来源:https://stackoverflow.com/questions/18178862/android-activity-open-on-the-emulator-but-not-in-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!