我是Java和android編程的新手。我在Toast消息後添加了一個代碼,用於在接口之間切換到我的應用程序,但是當我啓動程序時,在Toast消息之後,它只停留在同一個接口中,而沒有提供任何錯誤。Android(Eclipse)Startactivity沒有迴應
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://xxx/xxx.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpclient.execute(httppost, responseHandler);
String reverseString = response;
if (reverseString =="success"){
Toast.makeText(this, reverseString, Toast.LENGTH_LONG).show();
//setContentView(R.layout.activity_main);
startActivity(new Intent(registergame.this, (MainActivity.class)));
finish();
}else{
Toast.makeText(this, reverseString, Toast.LENGTH_LONG).show();
}
} catch (ClientProtocolException e) {
Toast.makeText(this, "CPE response " + e.toString(), Toast.LENGTH_LONG).show();
// TODO Auto-generated catch block
} catch (IOException e) {
Toast.makeText(this, "IOE response " + e.toString(), Toast.LENGTH_LONG).show();
// TODO Auto-generated catch block
}
和我的清單文件;
<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=".deneme"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.baglanti.DENEME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".registergame"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.baglanti.REGISTER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
也試過
startActivity(new Intent("android.intent.action.MAIN"));
但同樣的事情發生,它顯示敬酒消息,並保持這樣的,任何想法? 預先感謝您。
在startActivity(new Intent(registergame.this,(MainActivity.class)));不要使用registergame.this,請嘗試使用getApplicationContext()。 – ashwin1103 2015-03-19 08:55:29
您是否看到過Toast.makeText(this,reverseString,Toast.LENGTH_LONG).show(); – Amsheer 2015-03-19 08:55:57
ashwin,你寫了同樣的東西,我發佈:( – Faruk 2015-03-19 08:58:52