从片段重构到活动 [英] Refactoring from Fragments to Activities

查看:128
本文介绍了从片段重构到活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个有点绝望呼吁一些很好的建议。

This is a bit of a desperation call for some good advice.

我就开始做这涉及抽屉式导航作为应用程序的主菜单中的项目。看的Andr​​oid教程我跟着榜样,开始发展后,最重要的是。这例子是一个单一的活动取决于抽屉选择的选项,它取代了碎片。在某种程度上,我跟着这个设计,因为如果我发起活动抽屉里丢失了,并且活动将与发射过渡出现,并没有好看的。

I began doing a project which involves Navigation drawer as the main menu for the application. After looking at the Android tutorial I followed the example and start developing on top of that. That example is a single activity that replaces the fragments depending on the selected option in the drawer. In part, I followed this design because if I launched Activities the drawer was lost and the Activity would appear with the launching transition and didn't look nice at all.

现在,我的项目是一个不小。在开发过程中我面对的几个问题,如:

Now, my project is not a small one. During development I faced several issues like:


  • onResume没有呼吁片段(由于没有连接到几个活动,但一来代替。

  • 所有片段之间的数据应该通过单一的活动

  • 管理选项菜单中的ActionBar成为一个真正的痛苦。

  • 和很多人一样,我不记得现在

现在我面临的一个新问题。在片段之一,我需要有一个微调将切换这一个内部片段。当然,该片段将需要更改导航模式操作栏中。这是开发一个大难题,但现在我面临着一个更大的问题,一些碎片内失去活动场景(例如,如果他们被分离的)。

Now I am facing a new issue. In one of the fragments I need to have a Spinner that will switch fragments inside this one. And of course, the fragment will need to change the navigation mode in the action bar. This was a major headache to develop, but now I am facing a bigger problem with some fragments inside losing the activity context (like if they were detached).

这么多问题,我决定切换回整个应用活动(这是一个自定义的应用程序,将在短短的1片模式运行,因此没有对碎片的担忧)之后。因此,简而言之我期待的意见就少了痛苦的方式做到这一点。

After so many problems I just decided to switch back the whole app to Activities (this is a custom app that will run in just 1 tablet model, so no worries about fragmentation). So, in short I am looking for advice on the less painful way to do this.

我是一个非常紧迫的期限,导致我开始不实施设计(如一个完整的小白)。现在,我被击中了,如果我不缺钱,我会立即取消这个项目这么多的问题。

I am on a extremely tight deadline that lead me to start implementing without designing (like a complete noob). Now I am being hit with so many issues that, if I didn't need the money, I would cancel this project at once.

请帮帮忙!

推荐答案

我可以给一点建议,但可悲的是你的情况不能真正被这里的任何一个答案解决。

I can give a little advice, but sadly your situation can't really be solved by any one answer here.

首先,从设计片段切换到活动设计比开关相反的方式容易得多。实际上,你可以使用你之前的片段,只是在每次活动只加载片段1(或多个,如果你preFER)。

First off, switching from a Fragment design to an Activity design is a lot easier than switching the opposite way. You can actually use all of the fragments you had before, and just have each activity loading only 1 of the fragments (or multiple if you prefer).

此外,处理意图时(启动新的活动),后 startActivity()叫你可以调用 overridePendingTransition()做任何你想要的启动转换(或完全删除)。

Also, when handling Intents (starting new activity), after the startActivity() call you can call overridePendingTransition() to make the launching transition whatever you want (or remove it completely).

这篇关于从片段重构到活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆