退出android

时间:2018-05-31 06:23:39

标签: java android

我一直在开发一个应用程序,其中我有一个与活动通信的片段。 在那个通信我已经应用了共享元素转换,到目前为止它工作但问题出现当我退出活动并返回片段两秒后片段开始重新加载我试图寻找一个可能的解决方案,但无法找到原因所以我我希望有人可以帮助我。

更新:因为我已经使用了动画的共享元素转换,我注意到没有转换背面按下片段没有被重新创建并且它工作正常但是动画它会在几秒钟后再次重新创建。 /强> 这是我的片段代码

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_feed, container, false);
        getActivity().getWindow().setExitTransition(null);
        setRetainInstance(true);
        toolbar = (Toolbar)view.findViewById(R.id.toolbar);
        // ((MainActivity)getActivity()).setSupportActionBar(toolbar);
        feed_recycler_view = (RecyclerView)view.findViewById(R.id.feed_recycler_view);
        //ViewCompat.setNestedScrollingEnabled(feed_recycler_view, false  );
        CustomTextView customTextView = (CustomTextView)toolbar.findViewById(R.id.toolbar_title);


        feed_layout_manager = new LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false);
        feed_recycler_view.setLayoutManager(feed_layout_manager);
        //feed_recycler_view.setNestedScrollingEnabled(false);
        feed_recycler_view.setHasFixedSize(true);
        feed_adapter = new FeedAdapter(FeedUtils.generateFeeds(getContext()),this);
        feed_recycler_view.setAdapter(feed_adapter);
        return view;
    }

    public static FeedFragment newInstance() {
        FeedFragment fragment = new FeedFragment();
        return fragment;
    }

    public static void applyFont(CustomTextView tv, Activity context) {
        tv.setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/Quicksand-Medium.ttf"));
    }
    @Override
    public boolean onBackPressed() {
        return false;
    }

    @Override
    public void onFeedItemClick(int pos, Feed_Data_Provider feedDataProvider, AppCompatImageView shareImageView) {
        Intent intent = new Intent(getContext(), ChatActivity.class);
        intent.putExtra(EXTRA_FEED_ITEM, feedDataProvider);
        intent.putExtra(EXTRA_FEED_IMAGE_TRANSITION_NAME, ViewCompat.getTransitionName(shareImageView));

        ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
                getActivity(),
                shareImageView,
                ViewCompat.getTransitionName(shareImageView));

        startActivity(intent, options.toBundle());
    }
}

这是活动类

public class ChatActivity extends AppCompatActivity {
        AppCompatImageView chat_image;
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat);
        getWindow().setEnterTransition(null);
        Bundle extras = getIntent().getExtras();
        Feed_Data_Provider feedItem = extras.getParcelable(FeedFragment.EXTRA_FEED_ITEM);
        chat_image = (AppCompatImageView)findViewById(R.id.chat_image);
        postponeEnterTransition();
        int imageUrl =feedItem.getClub_image();
        supportPostponeEnterTransition();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            String imageTransitionName = extras.getString(FeedFragment.EXTRA_FEED_IMAGE_TRANSITION_NAME);
            if (imageTransitionName != null) {
                chat_image.setTransitionName(imageTransitionName);
            }
        }
        Glide.with(this)
                .load(imageUrl)
                .listener(new RequestListener<Drawable>() {
                    @Override
                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                        supportStartPostponedEnterTransition();
                        return false;

                    }

                    @Override
                    public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                        supportStartPostponedEnterTransition();
                        return false;
                    }
                })
                .into(chat_image);

    }


}

0 个答案:

没有答案