2015-03-19 30 views
-3

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

但同樣的事情發生,它顯示敬酒消息,並保持這樣的,任何想法? 預先感謝您。

+0

在startActivity(new Intent(registergame.this,(MainActivity.class)));不要使用registergame.this,請嘗試使用getApplicationContext()。 – ashwin1103 2015-03-19 08:55:29

+0

您是否看到過Toast.makeText(this,reverseString,Toast.LENGTH_LONG).show(); – Amsheer 2015-03-19 08:55:57

+0

ashwin,你寫了同樣的東西,我發佈:( – Faruk 2015-03-19 08:58:52

回答

1

有一次,我也面臨同樣的問題。當我需要閱讀回覆,如果它「成功」,然後允許下一個活動。在我的情況下,我有「如果」條件的問題。也就是說,而不是這個if (reverseString =="success")

只是嘗試

if (reverseString.contains("success")) 

我想評論這樣說。但是在這裏說的很冗長。也許它會有所幫助。我不確定。

注意:@回覆評論 你必須看到吐司。因爲你在if和else中添加相同的東西。從其他人中刪除吐司,看到你看不到吐司。那是因爲你的條件失敗。

+0

哇它的工作,非常阿姆謝爾,我不認爲「如果」可能會導致這種錯誤 – Faruk 2015-03-19 09:02:34

+0

對不起,我的英文很弱,我不明白,你是什麼意思,我的回答是否正常? – Amsheer 2015-03-19 09:03:48

+0

工作,謝謝 – Faruk 2015-03-19 09:07:11