从标签活动回到其他活动后,无法销毁活动

时间:2016-09-23 12:57:13

标签: android android-activity tabs destroy

您好我有两个活动,一个是正常活动,另一个包含两个标签,它们是片段。当从包含活动的标签返回到正常活动时,应用程序崩溃并跟随堆栈跟踪。

unable to destroy activity android java.lang.IllegalArgumentException: parameter must be a descendant of this view

这是我的正常活动代码(ListitemsData和我一起)

package com.dev.retailer;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.dev.adapter.GridViewofferadapter;
import com.dev.adapter.ProductListAdapter;
import com.dev.database.Repo;
import com.dev.fragment.QuizFragment;
import com.dev.model.ListDetails;
import com.dev.model.OpportunityPhotos;
import com.dev.model.OpportunityTable;
import com.dev.model.VendorAddressTable;
import com.dev.model.VendorTable;
import com.dev.model.offer_category_type;
import com.dev.rprtgnet.CategorySelectionActivity;
import com.dev.rprtgnet.R;
import com.dev.rprtgnet.SignInActivity;
import com.dev.sharedpreferences.SessionManager;
import com.dev.volley.AppController;
import com.facebook.login.LoginManager;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HTTP;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import java.util.concurrent.CopyOnWriteArrayList;

public class RetailerOfferViewPage extends AppCompatActivity implements OnItemClickListener
         {

    RecyclerView Viewoffergrid;
    RecyclerView lstview;
    public static CopyOnWriteArrayList<ListDetails> ListItemsData;
    protected Repo repoObject;
    private EditText searchedit;
    private SessionManager session;
    private ProductListAdapter mProductListAdapter;
    private RetailerOfferViewPage context;
    GridViewofferadapter customAdapter;
    int pendingRequests = 0;
    private  GoogleApiClient mGoogleApiClient;


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(com.dev.rprtgnet.R.layout.retailer_offer_viewpage);

        context = this;


        this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        final EditText searchfilter = (EditText) findViewById(R.id.searchfilter);
        final ImageView cancel = (ImageView) findViewById(R.id.cancel);
        final ImageView gridview = (ImageView) findViewById(com.dev.rprtgnet.R.id.gridview);
        final ImageView listview = (ImageView) findViewById(com.dev.rprtgnet.R.id.listview);


        /*mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(Plus.API)
                .addScope(Plus.SCOPE_PLUS_LOGIN).build();*/

        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                searchfilter.setText("");
            }
        });


        searchfilter.addTextChangedListener(new TextWatcher() {

            @Override
            public void afterTextChanged(Editable arg0) {
                // TODO Auto-generated method stub
                String text = searchfilter.getText().toString().toLowerCase(Locale.getDefault());


                if(gridview.getVisibility() == View.VISIBLE)
                {
                    if(mProductListAdapter != null) {
                        mProductListAdapter.filter(text);
                    }
                }
                else if(listview.getVisibility() == View.VISIBLE)
                {
                    customAdapter.filter(text);
                }
            }

            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1,
                                          int arg2, int arg3) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onTextChanged(CharSequence arg0, int arg1, int arg2,
                                      int arg3) {
                // TODO Auto-generated method stub
            }
        });

        if(mProductListAdapter != null)
        {
            mProductListAdapter.notifyDataSetChanged();
        }

        Button logout = (Button) findViewById(com.dev.rprtgnet.R.id.Logoutbtn);

        lstview = (RecyclerView) findViewById(com.dev.rprtgnet.R.id.ResList);

        LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
        lstview.setLayoutManager(mLayoutManager);

        if (logout != null) {
            logout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    LogoutApp();
                }
            });
        }

        ImageButton back = (ImageButton) findViewById(com.dev.rprtgnet.R.id.back);

        if (back != null) {
            back.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    onBackPressed();
                }
            });
        }

        Button searchbtn = (Button) findViewById(com.dev.rprtgnet.R.id.searchbtn);
        searchedit = (EditText) findViewById(com.dev.rprtgnet.R.id.searchbox);
        session = SessionManager.getInstance(getBaseContext());



        assert listview != null;
        listview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                listview.setVisibility(View.GONE);
                if (gridview != null) {
                    gridview.setVisibility(View.VISIBLE);
                }
                lstview.setVisibility(View.VISIBLE);
                Viewoffergrid.setVisibility(View.GONE);
                lstview = (RecyclerView) findViewById(com.dev.rprtgnet.R.id.ResList);
                LinearLayoutManager mLayoutManager = new LinearLayoutManager(context);
                lstview.setLayoutManager(mLayoutManager);
                mProductListAdapter = new ProductListAdapter(context,
                        mProductListAdapter, lstview , ListItemsData, "VenderList");
                lstview.setAdapter(mProductListAdapter);
                mProductListAdapter.notifyDataSetChanged();
            }
        });


        if (gridview != null) {
            gridview.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View arg0) {
                    gridview.setVisibility(View.GONE);
                    listview.setVisibility(View.VISIBLE);
                    Viewoffergrid.setVisibility(View.VISIBLE);
                    lstview.setVisibility(View.GONE);
                    Viewoffergrid = (RecyclerView) findViewById(com.dev.rprtgnet.R.id.offersgridview);
                     customAdapter = new GridViewofferadapter(context, ListItemsData);
                    Viewoffergrid.setAdapter(customAdapter);
                    customAdapter.notifyDataSetChanged();
                }
            });
        }



        Viewoffergrid = (RecyclerView) findViewById(com.dev.rprtgnet.R.id.offersgridview);


        GetOpportunityList();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
    }





    private boolean LogoutApp() {
        try {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(
                    RetailerOfferViewPage.this);
            alertDialog.setTitle("Logout Application?");
            alertDialog
                    .setMessage("Are you sure you want to Logout from the application?");
            alertDialog.setIcon(com.dev.rprtgnet.R.drawable.ic_logout);
            alertDialog.setPositiveButton("Yes",
                    new DialogInterface.OnClickListener() {
                        @SuppressLint("InlinedApi")
                        public void onClick(DialogInterface dialog, int which) {
                            //CategorySelectionActivity.LoginLogoutTag = "Login";
                            session.createRegUserName("User Name");
                            CategorySelectionActivity.User_Name.setText( session.getRegUserName());
                            QuizFragment.Emailaddress = null;
                            QuizFragment.mobileno = null;
                            QuizFragment.password = null;
                            QuizFragment.Photoname = null;
                            QuizFragment.UserRegId=null;
                            session.createLoginSession(getString(com.dev.rprtgnet.R.string.main_RETAILER));
                            session.createEmail(QuizFragment.Emailaddress);
                            session.createMobileNo(QuizFragment.mobileno);
                            session.createPassword(QuizFragment.password);
                            session.createUserRegisterID(null);
                            session.createPhotoname(QuizFragment.Photoname);

                            session.createLoginType(null);

                           /* Intent intent = new Intent(context, CategorySelectionActivity.class);
                            startActivity(intent);*/

                            /*if (AccessToken.getCurrentAccessToken() == null) {
                                Toast.makeText(getApplicationContext(),"Logged Out",Toast.LENGTH_SHORT).show();
                                Intent i=new Intent(getApplicationContext(),CategorySelectionActivity.class);
                                startActivity(i);

                                return; // already logged out

                            }

                            new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/permissions/", null, HttpMethod.DELETE, new GraphRequest
                                    .Callback() {
                                @Override
                                public void onCompleted(GraphResponse graphResponse) {

                                    LoginManager.getInstance().logOut();

                                }
                            }).executeAsync();*/

                            Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
                                    new ResultCallback<Status>() {
                                        @Override
                                        public void onResult(Status status) {
                                            // ...
                                            LoginManager.getInstance().logOut();
                                            Toast.makeText(getApplicationContext(),"Logged Out",Toast.LENGTH_SHORT).show();
                                            Intent i=new Intent(getApplicationContext(),CategorySelectionActivity.class);
                                            startActivity(i);
                                        }
                                    });


                            /*Auth.GoogleSignInApi.signOut(QuizFragment.mGoogleApiClient).setResultCallback(
                                    new ResultCallback<Status>() {
                                        @Override
                                        public void onResult(Status status) {

                                        }
                                    });*/




                        }
                    });
            alertDialog.setNegativeButton("No",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
            alertDialog.show();
            return true;
        } catch (Exception e) {
            e.printStackTrace();

            return false;
        }
    }


    private void GetOpportunityList() {


                    mProductListAdapter = new ProductListAdapter(this,
                            mProductListAdapter, lstview , ListItemsData, "VenderList");
                    lstview.setAdapter(mProductListAdapter);
                    mProductListAdapter.notifyDataSetChanged();


                }

            }
        } catch (Exception e) {
            e.printStackTrace();

        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
                            long id) {

        ListDetails product = ListItemsData
                .get(position);



    }



    @Override
    public void onPause() {
        Log.e("DEBUG", "OnPause of RetailerOfferViewPage");
        super.onPause();
    }

    @Override
    public void onStart() {
        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .build();
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .build();
        mGoogleApiClient.connect();
        super.onStart();

    }

    @Override
    public void onStop() {
        super.onStop();

    }

}

这是我的标签活动

package com.dev.tabsswipe;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.dev.model.UserBlockList;
import com.dev.rprtgnet.R;
import com.dev.rprtgnet.SignInActivity;
import com.dev.volley.AppController;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import java.util.concurrent.CopyOnWriteArrayList;

public class SimpleTabsActivity extends AppCompatActivity {

    public static int gridOppId;

    final int[] ICONS = new int[]{
            R.drawable.userw,R.drawable.userw,
    };
    ViewPager viewPager;
    CopyOnWriteArrayList<UserBlockList> ArrayList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test2);

       // finish();

        ImageButton back = (ImageButton) findViewById(com.dev.rprtgnet.R.id.back);

        if (back != null) {
            back.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    onBackPressed();
                }
            });
        }


        /*Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);*/

        //if (enableBackNavigation) {
           // toolbar.setNavigationIcon(R.drawable.ic_back);
        //assert toolbar != null;
        /*toolbar.setNavigationOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    try {
                        onBackPressed();
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                    }

                }
            });*/
       // }

        Intent mIntent = getIntent();
        if (mIntent != null) {
            gridOppId = mIntent.getIntExtra("OppId", 0);
        }


        GetReservedoffersList();
       // getSupportActionBar().setDisplayHomeAsUpEnabled(true);

         viewPager = (ViewPager) findViewById(R.id.viewpager);
        setupViewPager(viewPager);


    }







    private void setupViewPager(ViewPager viewPager) {
        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
        adapter.addFragment(new DetailsReservation(), "Details");
        adapter.addFragment(new ReserveUserListTabs(), "ReserveList");


        viewPager.setAdapter(adapter);
    }

    class ViewPagerAdapter extends FragmentPagerAdapter {
        private final List<Fragment> mFragmentList = new ArrayList<>();
        private final List<String> mFragmentTitleList = new ArrayList<>();

        public ViewPagerAdapter(FragmentManager manager) {
            super(manager);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragmentList.get(position);
        }

        @Override
        public int getCount() {
            return mFragmentList.size();
        }

        public void addFragment(Fragment fragment, String title) {
            mFragmentList.add(fragment);
            mFragmentTitleList.add(title);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentTitleList.get(position);
        }
    }
}

我将这个标签活动从适配器clas调用为

holder.parentcv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (UserType.equals("VenderList")) {
                    GridViewofferadapter.gridClickpos = position;
                    ListDetails product = worldpopulationlist.get(position);
                    int oppId = Integer.parseInt(product.getOfferID());
                    Intent i = new Intent(context, SimpleTabsActivity.class);
                    ReserveUserList.setOpportunityId(oppId);
                    i.putExtra("OppId", oppId);
                    i.putExtra("gridClickpos", position);
                   // i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(i);
                    //context.finish();
                } else {
                    mOnItemClickListListener.onClick(v, position);
                }
            }
        });

我在哪里做错了请帮助我。

0 个答案:

没有答案