开发者

fragments best practice [closed]

开发者 https://www.devze.com 2023-04-09 06:08 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

I have a content provider in my Android 3.1 Application, and are calling startActivity() with Intents that has content://my.package/xxx Uris, and Intent.ACTION_VIEW actions. In my andoroid-manifest.xml I have my content provider's mime-types set up so that my Activity picks up the intents. Evert thing works fine.

Here is my situation

  • When an Activity with fragments is drawn, all fragments receive their life cycle events.
  • I don't want all fragments to be redrawn/updated on the Intent. Because the incoming URI is usually just passed along to a the query method on my开发者_高级运维 content provider. The intent is usually only relevant to a specific fragment.

How do I stop things from happening in fragments that has nothing to do with the current Intent?


Can you post some code that's relevant to your problem? In particular, the portion of yoru Activity class code that deals with Fragment management, and the layout's .xml file?

If you are declaring the fragments directly in the layout's .xml file, the fragments will be instantiated every time. If you do not want this behavior, instantiate and add fragments only programmatically (using FragmentTransacations with the FragmentManager in your activity code, and remove them from the .xml declaration.

0

精彩评论

暂无评论...
验证码 换一张
取 消