【问题标题】:Android - Activity open on the emulator but not in deviceAndroid - 活动在模拟器上打开但不在设备中
【发布时间】:2013-08-13 06:50:04
【问题描述】:

我在 android 中开发了一个小项目并在模拟器上运行正常,但在我的设备中只显示第一个 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());

}

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>

清单:

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

所以,我在模拟器 2.3.3 上正常运行,但在我的设备 android 2.3.4 上无法运行

有什么问题吗?

谢谢。

【问题讨论】:

  • 你是否尝试将 android:targetSdkVersion 设置为 11 并尝试一次..
  • 那么第二个活动是从第一个活动开始的?
  • @Sushil 是的,我尝试过但不起作用
  • 您的物理 Android 设备是否有外部目录(外部 SD 卡)?
  • @DroidMatt 是的,第一个活动只是一个按钮启动

标签: android android-activity foreach datasource


【解决方案1】:

您是否对两个活动使用相同的布局?我认为您使用的布局与此行通常显示第一个活动布局相同:setContentView(R.layout.main);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-08
    • 1970-01-01
    • 1970-01-01
    • 2011-02-15
    • 2012-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多