让Android应用在Android 2.3.6设备和所有4.x虚拟设备上正常运行。但是我收到一个用户的报告,在运行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;
}
}
List.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>
Simplerow.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>
答案 0 :(得分:0)
最后想到这一点,它实际上是由长时间运行的asynctask引起的。只要doInBackground正在运行它就不会启动ListActivity - 当你切换到另一个应用程序时,doInBackground将停止并且ListActivity将被启动。通过将asynctask中处理的东西移动到线程/处理程序来对其进行排序。