1

拥有可在 Android 2.3.6 设备和所有 4.x 虚拟设备上正常运行的 Android 应用程序。但是,我收到一位用户的报告,称在运行 4.0.4 - 4.1.1 的多台设备上,除非您转到另一个应用程序并再次返回,否则一个活动不会显示。我已经尝试了我能想到的一切,但没有任何区别,而且由于我无法在虚拟设备上重现该错误,因此我无法自己调试(或测试)它。这是一个视频剪辑,显示了该用户发生的事情:Youtube

未显示的活动的调用是这样的:

Intent stationList = new Intent(LoggedIn.this, StationList.class);
  stationList.putExtra("stationlist", stationlist);
startActivityForResult(stationList, 1);

站名单活动内容:

public class StationList extends ListActivity {

private ListView list ;  
  private ArrayAdapter<String> listAdapter ;

  @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
      if(keyCode==KeyEvent.KEYCODE_BACK)

          {
          Intent returnIntent = new Intent();

       setResult(RESULT_CANCELED,returnIntent);     
       finish();    

          }
        return true;
    }

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.list);

    // Find the ListView resource.   
    list = (ListView) findViewById( android.R.id.list );  

    // Create and populate a List of stations.  
     String stationlist = getIntent().getExtras().getString("stationlist");

    final String[] stationListArray = stationlist.split("\n");

    ArrayList<String> stationList = new ArrayList<String>();  
    stationList.addAll( Arrays.asList(stationListArray) );  


    // Create ArrayAdapter using the station list.  
    listAdapter = new ArrayAdapter<String>(StationList.this, R.layout.simplerow, stationList);  


    // Set the ArrayAdapter as the ListView's adapter.  
    list.setAdapter( listAdapter ); 



    list.setOnItemClickListener(new OnItemClickListener() {
           @Override
           public void onItemClick(AdapterView<?> list, View view, 
             int position, long id) { 
           // Get the cursor, positioned to the corresponding row in the result set
               String channel = "echo -n 'notempty' > ~/.config/pianobar/stationcreate && echo '" + position + "' >> ~/.config/pianobar/ctl";
               Toast.makeText(getApplicationContext(),
                         "Starting station " + stationListArray[position] +", please wait", Toast.LENGTH_LONG).show();    


               Intent returnIntent = new Intent();
               returnIntent.putExtra("channel",channel);
               setResult(RESULT_OK,returnIntent);     
               finish();            

           }
          });


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_station_list, menu);
    return true;
}
}

列表.xml:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="horizontal"
 tools:context=".StationList" >
 <ListView android:layout_width="fill_parent"   
   android:layout_height="fill_parent"   
   android:id="@android:id/list">  
 </ListView>  
<TextView
      android:id="@android:id/empty"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center"
      android:text="Loading station data..." />
</LinearLayout>

简单行.xml:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"  
android:id="@+id/rowTextView"   
android:layout_width="fill_parent"   
android:layout_height="wrap_content"  
android:padding="10dp"  
android:textSize="16sp" >  
</TextView>
4

1 回答 1

0

终于弄明白了,其实是长时间运行的异步任务造成的。只要 doInBackground 正在运行,它就不会启动 ListActivity - 当您切换到另一个应用程序时,doInBackground 将停止并启动 ListActivity。通过将 asynctask 中处理的内容移动到线程/处理程序来对其进行排序。

于 2013-03-20T15:29:34.183 回答