How do I identify that I'm interacting with a fragment? My understanding about fragments is not quite clear and I presume that they are about UI, always requires an Activity to be shown with it and are supposed to be modular in nature. They do not come with their own View unlike a full blown Activity.

Anyhow, here's the problem: the app My Android Tools offers UI that appears to be multi-pane and multi-window. For example: if I launch the app and choose Database, the activity remains the same i.e. cn.wq.myandroidtools/.MainActivity but the view on the UI changes. If I choose SharedPreferences the Activity still remains the same yet the view on the UI changes.

(Click an image to enlarge it)


Here's what I've tried:

  • I've closely monitored logcat and it didn't reveal anything useful.
  • I've tried dumpsys activity window windows and other than the same activity I didn't find anything of use to me.
  • I've tried dumpsys activity activities and dumpsys activity -p cn.wq.myandroidtools. Former didn't yield anything significant and the latter provided output which multiple mentions of the term fragments, yet I couldn't understand what I was dealing with.
  • I've already checked the manifest and there is no Activity that points to the entry Database would cause to open.

Assuming a fragment may be misinterpretation but then how would I verify I'm wrong?

There's more: this is not an XY problem. Yes, I can look for an app that offers the same feature which the said app provides under Database entry. I already found two alternatives and I don't want to use them.

Why? Because I want to learn since fragments are not limited to the said app but are used heavily by Settings app and many other apps out in the wild. If only I get to understand what particular fragment I'm dealing with, I may be able to use this answer to always have the said app show the UI meant for Database entry, whenever launched from app drawer.

In short

  • I'm looking for a way to realize that I'm interacting with a fragment;
  • What about that fragment do I need to use in this answer to show it?

If it is of importance: I'm using Nexus 6 with stock and rooted Android 6.0.1. It would be fine if you provide answers tested on stock Android 5.0.x or 5.1.x.

  • dumpsys activity top,this command will show the detail of the current activity,containing the current fragment. – wangqi060934 Jul 14 '17 at 3:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.