2012-03-17 83 views
0

通過使用選項卡組acitvity,我有四個選項卡。單擊後退按鈕時出現故障,但我想要在每個選項卡中執行第一個活動時遇到問題。後退按鈕在TabGroup活動中強制關閉

這裏是我的代碼TabHome.java

super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.tab); 

     Resources res = getResources(); 
     tabs = getTabHost(); 
     TabHost.TabSpec spec; 
     Intent intent; 

     // Create an Intent to launch an Activity for the tab (to be reused) 
     //1 -Gebrauchte Tab 
     intent = new Intent().setClass(this,TabBikesGroupActivity.class); 

     // Initialize a TabSpec for each tab and add it to the TabHost 
     spec = tabs.newTabSpec("gebrauchte").setIndicator("Gebrauchte", 
          res.getDrawable(R.drawable.bike)) 
         .setContent(intent); 
     tabs.addTab(spec); 


     //2 - Produkte 
     intent = new Intent().setClass(this, TabProductGroupActivity.class); 
     spec = tabs.newTabSpec("produkte").setIndicator("Produkte", 
          res.getDrawable(R.drawable.t_produkt)) 
         .setContent(intent); 
     tabs.addTab(spec); 

     //3 - Handler 
     intent = new Intent().setClass(this, TabDealersGroupActivity.class); 
     spec = tabs.newTabSpec("handler").setIndicator("Handler", 
          res.getDrawable(R.drawable.haendler)) 
         .setContent(intent); 
     tabs.addTab(spec); 

     //4 - Einstellungen 
     intent = new Intent().setClass(this, TabSettingsGroupActivity.class); 
     spec = tabs.newTabSpec("einstellungen").setIndicator("Einstellungen", 
          res.getDrawable(R.drawable.t_settings)) 
         .setContent(intent); 


     tabs.addTab(spec); 

    // tabHost.setCurrentTab(1); 

    } 

    public void switchToTab(int tabid){ 
     System.out.println("CURRENT TAB "+tabid); 
     tabs.setCurrentTab(tabid); 
} 

上面的代碼describs約tabgroup活動

和 這是我的第一個選項卡DealersDetailDisplay.java

In that i'm having two button and calling the below methods.When i click on this buttons goes to (Bike search list Activity -> Image adapter -> details activity ->search list Activity -> image adapter -> details activity -> goes same like above)infinite times.Now my problem is when i click on the back button then needs to move activity up to first Bike search list Activity. 

這是我的兩個按鈕動作聽衆.....

btnAllBikeDetail.setOnClickListener(new OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       getBikeSearchForDealer(dealerId); 
      } 
     }); 

    btnAllProductDetail.setOnClickListener(new View.OnClickListener() { 


      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       getProductSearchForDealer(); 
      } 
     }); 

以下兩種方法是從特定網址獲取數據並在另一個活動中列出。之後,如果我選擇特定列表項目,然後移動到另一個活動(即圖像適配器),然後再次單擊它移動到另一個活動再次,你得到上面的兩個按鈕(相同的動作)這將去喜歡這個汽車無...

protected void getBikeSearchForDealer(String dealerId) { 
     // TODO Auto-generated method stub 
     try { 
      URL url = URLComposer.getMotorCycleListUsedByDealerURL(dealerId); 
      System.out.println("URL " + url.toString()); 

      Intent intent=new Intent(getParent(),BikesList.class);    
      intent.putExtra("Search_Result",url.toString()); 
      TabGroupActivity parentActivity =(TabGroupActivity) getParent(); 
      parentActivity.startChildActivity("BikeSearch", intent); 
     } catch (MalformedURLException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 

    protected void getProductSearchForDealer() { 
     // TODO Auto-generated method stub 
     try { 
      URL url = URLComposer.getDealersProductListURL(dealerId); 
      System.out.println("URL " + url.toString()); 

      Intent intent = new Intent(getParent(), ProductList.class); 

      TabGroupActivity parentActivity = (TabGroupActivity) getParent(); 
      intent.putExtra("Dealer_Search_Result",  url.toString());   
      parentActivity.startChildActivity("productList", 
        intent); 
      System.out.println("URL " + url.toString()); 
     } catch (MalformedURLException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 
Logcat result is 

03-17 14:37:59.760: I/System.out(585): Gallery position :http://www.1000ps.at//images/gebrauchtmotorrad/g_G625147_2.jpg 
03-17 14:37:59.900: D/dalvikvm(585): GC_FOR_MALLOC freed 12364 objects/869712 bytes in 132ms 
03-17 14:37:59.931: D/webviewglue(585): nativeDestroy view: 0x3d60c0 
03-17 14:37:59.940: D/webviewglue(585): nativeDestroy view: 0x354ac8 
03-17 14:38:03.620: I/System.out(585): Gallery position :http://www.1000ps.at//images/gebrauchtmotorrad/g_G625147_3.jpg 
03-17 14:38:06.151: I/System.out(585): Gallery position :http://www.1000ps.at//images/gebrauchtmotorrad/g_G625147_3.jpg 
03-17 14:38:06.301: D/dalvikvm(585): GC_EXTERNAL_ALLOC freed 4806 objects/406080 bytes in 147ms 
03-17 14:38:06.320: D/webviewglue(585): nativeDestroy view: 0x35c568 
03-17 14:38:06.361: D/skia(585): --- decoder->decode returned false 
03-17 14:38:08.303: I/System.out(585): Gallery position :http://www.1000ps.at//images/gebrauchtmotorrad/g_G625147_3.jpg 
03-17 14:38:12.480: I/System.out(585): Gallery position :http://www.1000ps.at//images/gebrauchtmotorrad/g_G625147_2.jpg 
03-17 14:38:23.981: I/System.out(585): hasUsedBikesnull 
03-17 14:38:23.981: I/System.out(585): hasUsedProductsnull 
03-17 14:38:24.081: I/System.out(585): hsdjka265204 
03-17 14:38:26.191: I/System.out(585): bikeOrder bikeID265204 
03-17 14:38:26.191: I/System.out(585): bikeOrder bikeId:265204 
03-17 14:38:26.191: I/System.out(585): XML Valueshttp://iphone.1000ps.at/iphone-xml/gebrauchte_suche_result.ashx?suchen_member=265204 
03-17 14:38:26.191: I/System.out(585): URL http://iphone.1000ps.at/iphone-xml/gebrauchte_suche_result.ashx?suchen_member=265204 
03-17 14:38:26.241: I/System.out(585): Override const 
03-17 14:38:26.860: I/System.out(585): Hitting the webservice 
03-17 14:38:26.860: I/System.out(585): DOM :[email protected] 
03-17 14:38:26.860: I/root node of document(585): BikeResults 
03-17 14:38:26.860: I/System.out(585): welcome 
03-17 14:38:26.860: I/System.out(585): welcome 
03-17 14:38:26.860: I/System.out(585): welcome 
03-17 14:38:26.870: I/System.out(585): welcome 
03-17 14:38:26.870: I/System.out(585): welcome 
03-17 14:38:26.880: I/System.out(585): bikeItemListSize5 
03-17 14:38:27.001: I/System.out(585): Pending View 
03-17 14:38:27.011: I/System.out(585): Override const 
03-17 14:38:27.550: I/System.out(585): Hitting the webservice 
03-17 14:38:27.680: I/System.out(585): DOM :[email protected] 
03-17 14:38:27.690: I/root node of document(585): BikeResults 
03-17 14:38:29.070: I/System.out(585): Override const 
03-17 14:38:29.070: I/System.out(585): XML Valueshttp://iphone.1000ps.at/iphone-xml/gebrauchte_detail.ashx?gid=559645 
03-17 14:38:29.640: I/System.out(585): Hitting the webservice 
03-17 14:38:29.640: I/System.out(585): DOM :[email protected] 
03-17 14:38:29.640: I/root node of document(585): document 
03-17 14:38:29.670: I/System.out(585): BikeDataSerive, biekId: 559645 
03-17 14:38:29.680: I/node list name(585): [email protected] 
03-17 14:38:29.680: I/node values(585): 1 
03-17 14:38:29.680: I/node list name(585): [email protected] 
03-17 14:38:29.680: I/node values(585): 1 
03-17 14:38:29.680: I/System.out(585): Thumbnail images http://www.1000ps.at//images/gebrauchtmotorrad/g_559645.jpg 
03-17 14:38:29.680: I/System.out(585): Thumbnail images http://www.1000ps.at//images/gebrauchtmotorrad/g_559645_2.jpg 
03-17 14:38:29.680: I/System.out(585): Thumbnail images http://www.1000ps.at//images/gebrauchtmotorrad/g_559645_3.jpg 
03-17 14:38:29.690: I/System.out(585): Thumbnail images http://www.1000ps.at//images/gebrauchtmotorrad/g_559645_4.jpg 
03-17 14:38:29.690: I/System.out(585): Original images http://www.1000ps.at//images/gebrauchtmotorrad/g_G559645.jpg 
03-17 14:38:29.690: I/System.out(585): Original images http://www.1000ps.at//images/gebrauchtmotorrad/g_G559645_2.jpg 
03-17 14:38:29.690: I/System.out(585): Original images http://www.1000ps.at//images/gebrauchtmotorrad/g_G559645_3.jpg 
03-17 14:38:29.690: I/System.out(585): Original images http://www.1000ps.at//images/gebrauchtmotorrad/g_G559645_4.jpg 
03-17 14:38:29.690: I/node list name(585): [email protected] 
03-17 14:38:29.690: I/node values(585): 1 
03-17 14:38:29.710: I/System.out(585): BikeDataService email:[email protected] 
03-17 14:38:29.710: I/System.out(585): kraft: null 
03-17 14:38:33.321: I/System.out(585): Activity Being closeActivities.BikeDetailsDisplay 
03-17 14:38:33.321: I/System.out(585): Destroy called 
03-17 14:38:34.460: I/System.out(585): Activity Being closeActivities.BikesList 
03-17 14:38:34.460: I/System.out(585): Destroy called 
03-17 14:38:35.261: I/System.out(585): Activity Being closeActivities.BikeOrder 
03-17 14:38:35.261: I/System.out(585): Destroy called 
03-17 14:38:35.261: W/System.err(585): java.lang.NullPointerException 
03-17 14:38:35.271: W/System.err(585): at com.InternetGMBH.ThousandPS.Activities.TabGroupActivity.finishFromChild(TabGroupActivity.java:54) 
03-17 14:38:35.271: W/System.err(585): at android.app.Activity.finish(Activity.java:3249) 
03-17 14:38:35.271: W/System.err(585): at com.InternetGMBH.ThousandPS.Activities.TabGroupActivity.onBackPressed(TabGroupActivity.java:108) 
03-17 14:38:35.271: W/System.err(585): at com.InternetGMBH.ThousandPS.Activities.BikeOrder$1.onClick(BikeOrder.java:134) 
03-17 14:38:35.271: W/System.err(585): at android.view.View.performClick(View.java:2408) 
03-17 14:38:35.281: W/System.err(585): at android.view.View$PerformClick.run(View.java:8816) 
03-17 14:38:35.281: W/System.err(585): at android.os.Handler.handleCallback(Handler.java:587) 
03-17 14:38:35.281: W/System.err(585): at android.os.Handler.dispatchMessage(Handler.java:92) 
03-17 14:38:35.281: W/System.err(585): at android.os.Looper.loop(Looper.java:123) 
03-17 14:38:35.281: W/System.err(585): at android.app.ActivityThread.main(ActivityThread.java:4627) 
03-17 14:38:35.281: W/System.err(585): at java.lang.reflect.Method.invokeNative(Native Method) 
03-17 14:38:35.281: W/System.err(585): at java.lang.reflect.Method.invoke(Method.java:521) 
03-17 14:38:35.281: W/System.err(585): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
03-17 14:38:35.281: W/System.err(585): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
03-17 14:38:35.281: W/System.err(585): at dalvik.system.NativeStart.main(Native Method) 
03-17 14:39:07.670: I/System.out(585): bikeOrder bikeID265204 
03-17 14:39:07.670: I/System.out(585): bikeOrder bikeId:265204 
03-17 14:39:07.670: I/System.out(585): XML Valueshttp://iphone.1000ps.at/iphone-xml/gebrauchte_suche_result.ashx?suchen_member=265204 
03-17 14:39:07.670: I/System.out(585): URL http://iphone.1000ps.at/iphone-xml/gebrauchte_suche_result.ashx?suchen_member=265204 
03-17 14:39:07.730: I/System.out(585): Override const 
03-17 14:39:09.020: I/System.out(585): Hitting the webservice 
03-17 14:39:09.020: I/System.out(585): DOM :[email protected] 
03-17 14:39:09.020: I/root node of document(585): BikeResults 
03-17 14:39:09.051: I/System.out(585): welcome 
03-17 14:39:09.051: I/System.out(585): welcome 
03-17 14:39:09.051: I/System.out(585): welcome 
03-17 14:39:09.051: I/System.out(585): welcome 
03-17 14:39:09.081: I/System.out(585): welcome 
03-17 14:39:09.110: I/System.out(585): bikeItemListSize5 
03-17 14:39:09.231: I/System.out(585): Pending View 
03-17 14:39:09.231: I/System.out(585): Override const 
03-17 14:39:10.520: I/System.out(585): Hitting the webservice 
03-17 14:39:10.720: I/System.out(585): DOM :[email protected] 
03-17 14:39:10.740: I/root node of document(585): BikeResults 
03-17 14:39:20.171: I/System.out(585): Activity Being closeActivities.BikesList 
03-17 14:39:20.171: I/System.out(585): Destroy called 
03-17 14:39:20.171: D/AndroidRuntime(585): Shutting down VM 
03-17 14:39:20.171: W/dalvikvm(585): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 
03-17 14:39:20.201: E/AndroidRuntime(585): FATAL EXCEPTION: main 
03-17 14:39:20.201: E/AndroidRuntime(585): java.lang.NullPointerException 
03-17 14:39:20.201: E/AndroidRuntime(585): at com.InternetGMBH.ThousandPS.Activities.TabGroupActivity.finishFromChild(TabGroupActivity.java:54) 
03-17 14:39:20.201: E/AndroidRuntime(585): at android.app.Activity.finish(Activity.java:3249) 
03-17 14:39:20.201: E/AndroidRuntime(585): at com.InternetGMBH.ThousandPS.Activities.TabGroupActivity.onBackPressed(TabGroupActivity.java:108) 
03-17 14:39:20.201: E/AndroidRuntime(585): at com.InternetGMBH.ThousandPS.Activities.BikesList$1.onClick(BikesList.java:67) 
03-17 14:39:20.201: E/AndroidRuntime(585): at android.view.View.performClick(View.java:2408) 
03-17 14:39:20.201: E/AndroidRuntime(585): at android.view.View$PerformClick.run(View.java:8816) 
03-17 14:39:20.201: E/AndroidRuntime(585): at android.os.Handler.handleCallback(Handler.java:587) 
03-17 14:39:20.201: E/AndroidRuntime(585): at android.os.Handler.dispatchMessage(Handler.java:92) 
03-17 14:39:20.201: E/AndroidRuntime(585): at android.os.Looper.loop(Looper.java:123) 
03-17 14:39:20.201: E/AndroidRuntime(585): at android.app.ActivityThread.main(ActivityThread.java:4627) 
03-17 14:39:20.201: E/AndroidRuntime(585): at java.lang.reflect.Method.invokeNative(Native Method) 
03-17 14:39:20.201: E/AndroidRuntime(585): at java.lang.reflect.Method.invoke(Method.java:521) 
03-17 14:39:20.201: E/AndroidRuntime(585): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
03-17 14:39:20.201: E/AndroidRuntime(585): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
03-17 14:39:20.201: E/AndroidRuntime(585): at dalvik.system.NativeStart.main(Native Method) 
03-17 14:40:25.580: I/Process(585): Sending signal. PID: 585 SIG: 9 

i have addressed only one cycle of activity is working...after that i am getting force close... 

only one time only the back button is working after that i am getting force close this is my logcat                    03-17 14:59:42.431: I/System.out(640): Activity Being closeActivities.BikeOrder 
03-17 14:59:42.431: I/System.out(640): Destroy called 
03-17 14:59:43.180: I/System.out(640): Activity Being closeActivities.BikeDetailsDisplay 
03-17 14:59:43.180: I/System.out(640): Destroy called 
03-17 14:59:44.360: I/System.out(640): Activity Being closeActivities.BikesList 
03-17 14:59:44.360: I/System.out(640): Destroy called 
03-17 14:59:44.390: D/AndroidRuntime(640): Shutting down VM 
03-17 14:59:44.390: W/dalvikvm(640): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 
03-17 14:59:44.400: E/AndroidRuntime(640): FATAL EXCEPTION: main 
03-17 14:59:44.400: E/AndroidRuntime(640): java.lang.NullPointerException 
03-17 14:59:44.400: E/AndroidRuntime(640): at com.InternetGMBH.ThousandPS.Activities.TabGroupActivity.finishFromChild(TabGroupActivity.java:54) 
03-17 14:59:44.400: E/AndroidRuntime(640): at android.app.Activity.finish(Activity.java:3249) 
03-17 14:59:44.400: E/AndroidRuntime(640): at com.InternetGMBH.ThousandPS.Activities.TabGroupActivity.onBackPressed(TabGroupActivity.java:108) 
03-17 14:59:44.400: E/AndroidRuntime(640): at com.InternetGMBH.ThousandPS.Activities.BikesList$1.onClick(BikesList.java:67) 
03-17 14:59:44.400: E/AndroidRuntime(640): at android.view.View.performClick(View.java:2408) 
03-17 14:59:44.400: E/AndroidRuntime(640): at android.view.View$PerformClick.run(View.java:8816) 
03-17 14:59:44.400: E/AndroidRuntime(640): at android.os.Handler.handleCallback(Handler.java:587) 
03-17 14:59:44.400: E/AndroidRuntime(640): at android.os.Handler.dispatchMessage(Handler.java:92) 
03-17 14:59:44.400: E/AndroidRuntime(640): at android.os.Looper.loop(Looper.java:123) 
03-17 14:59:44.400: E/AndroidRuntime(640): at android.app.ActivityThread.main(ActivityThread.java:4627) 
03-17 14:59:44.400: E/AndroidRuntime(640): at java.lang.reflect.Method.invokeNative(Native Method) 
03-17 14:59:44.400: E/AndroidRuntime(640): at java.lang.reflect.Method.invoke(Method.java:521) 
03-17 14:59:44.400: E/AndroidRuntime(640): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
03-17 14:59:44.400: E/AndroidRuntime(640): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
03-17 14:59:44.400: E/AndroidRuntime(640): at dalvik.system.NativeStart.main(Native Method) 
03-17 14:59:47.831: I/Process(640): Sending signal. PID: 640 SIG: 9 
+2

添加的logcat找出在碰撞發生。 – PravinCG 2012-03-17 06:49:11

回答

0

this會幫助你。這裏我正在處理攝像模式下的返回按鈕。

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
if (requestCode == CAMERA_REQUEST) { 
    Bitmap photo = (Bitmap) data.getExtras().get("data"); 

    if(photo != null) 
     imageView.setImageBitmap(photo); 
} 
} 

您還可以使用:

@Override 
public void onBackPressed() { 
//here is your code 
} 
+0

請編輯此答案,並在其中提供另一個答案,然後刪除它。 – Ghost 2012-03-17 07:04:57

+0

可以解釋清楚,因爲我使用tabgroup活動。 – saravana 2012-03-17 08:38:54