Android(Eclipse) Startactivity 没有响应

Android(Eclipse) Startactivity gives no response

我是 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"));

但同样的事情发生了,它显示吐司消息并保持这样,有什么想法吗? 提前谢谢你。

曾经我也遇到过同样的问题。当我需要阅读响应时,如果它 "success" 则允许下一个 Activity。就我而言,我对 "if" 条件有疑问。那不是这个 if (reverseString =="success")

试试

if (reverseString.contains("success"))

我想在评论中说这个。但是在这里说起来很冗长。也许它会有所帮助。我不确定。

注:@回复评论 你必须看到吐司。因为你在 if 和 else 中添加了同样的东西。从 else 中移除 Toast,看不到 toast。那是因为你的 if 条件失败了。