切换活动时,我似乎遇到了崩溃问题。我按照关于切换活动的标准教程,但他们目前正在导致应用程序崩溃。基本的想法是这样的。我有一种感觉,因为我正在运行一个异步线程,它引起了一个问题,即使它完全被卸载到另一个对象。有一个对象管理线程:
public class threads
{
public static threads Threads = new threads();
readThread mainReadThread;
writeThread mainWriteThread;
void startThreads()
{
if (mainReadThread == null && mainWriteThread == null)
{
mainWriteThread = new writeThread();
mainReadThread = new readThread();
mainReadThread.execute(0);
mainWriteThread.execute(0);
}
}
void pauseThreads()
{
if (mainReadThread != null && mainWriteThread != null)
{
//Pause thread
}
}
class writeThread extends AsyncTask<Object, Object, Object>
{
//do stuff...
}
class readThread extends AsyncTask<Object, Object, Object>
{
//do stuff
}
}
为了切换活动,我执行以下操作
getPlaytest.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//dataHolder.sendFlags.add(dataHolder.flags.playTestStarted);
Intent myIntent = new Intent(getApplicationContext(), currentPlaytest.class);
startActivity(myIntent);
}
});
新活动看起来像这样
public class currentPlaytest extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playtest);
dataHolder.application = getApplicationContext();
threads.Threads.startThreads();
// ToDo add your GUI initialization code here
}
}
dubugger目前没有告诉我为什么事情会崩溃。该应用程序只是崩溃,调试器断开连接。我正在使用NetBeans进行开发。据我所知,线程应该不是问题。有什么建议吗?
页面的xml是
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="apps.zombieYoga.statistics"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<activity android:name="MainActivity"
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="currentPlaytest"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.playtest" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
playtest XML的代码是
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=".NewActivityClassName"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/dataButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="List Sessions"
/>
</LinearLayout>