后退按钮在TabGroup活动中强制关闭

时间:2012-03-17 06:44:21

标签: android

我使用标签组acitvity有四个标签。点击后退按钮会出现问题但是我想在每个标签中进行第一次活动。

这是我的代码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);
}

上面的代码描述了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 :org.apache.harmony.xml.dom.DocumentImpl@450c69e0
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 :org.apache.harmony.xml.dom.DocumentImpl@45186100
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 :org.apache.harmony.xml.dom.DocumentImpl@451cad88
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): org.apache.harmony.xml.dom.NodeListImpl@450209a0
03-17 14:38:29.680: I/node values(585): 1
03-17 14:38:29.680: I/node list name(585): org.apache.harmony.xml.dom.NodeListImpl@450202a8
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): org.apache.harmony.xml.dom.NodeListImpl@4522a1c0
03-17 14:38:29.690: I/node values(585): 1
03-17 14:38:29.710: I/System.out(585): BikeDataService email:th.strassnitzky@utanet.at
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 :org.apache.harmony.xml.dom.DocumentImpl@451aca80
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 :org.apache.harmony.xml.dom.DocumentImpl@4529c450
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

1 个答案:

答案 0 :(得分: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
}