【发布时间】:2015-03-19 08:54:00
【问题描述】:
我是 Java 和 android 编程的新手。我在 toast 消息之后添加了一个代码来在我的应用程序的界面之间切换,但是当我启动程序时,在 toast 消息之后它只是停留在同一个界面中而不会出现任何错误。
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"));
但同样的事情发生了,它显示了 toast 消息并保持不变,有什么想法吗? 提前谢谢你。
【问题讨论】:
-
在 startActivity(new Intent(registergame.this, (MainActivity.class)));不要使用 registergame.this,而是尝试使用 getApplicationContext() 。
-
你看到这个吐司了吗 Toast.makeText(this, reverseString, Toast.LENGTH_LONG).show();
-
ashwin,你写了同样的东西,我发了:(
-
Amsheer 是的 toast 消息被看到,但之后没有任何反应:(
标签: java android eclipse android-layout android-intent