0

Assume there is a quite complicated open source Android Application. What I want to do is: to make a brand new Tabbed Activity inside the application and call/run an activity of the app in each tab. The called activity should run under the tab as if it was running on a normal window (or as if it was running on its own layout).

For instance; let the original project be a chat application with lots of services, permissions, activities, fragments etc one depending on another in a tangled fashion. In tab_1, I want to call the activity which lists the contacts. In tab_2, I want to call the activity which starts a conversation (brings chat screen - with a random person maybe - this is just an example). In tab_3 sent media is displayed. These activities all are included in the original project.

Now, it would be easy if I could turn the activities into fragments by doing;

class SomeProjectClass extends Fragment {...}

However SomeProjectClass already extends another class which is not Fragment. Is it possible to convert such an activity into a fragment? Or is there completely different way to embed the whole activity into a tab?

Maybe, instead of using a tabbed UI, I should simply add buttons to the action bar to navigate between the desired activities. But this would not have the aesthetics of the swipe move in tabbed screen.

Xfce4
  • 557
  • 5
  • 28
  • "Is it possible to convert such an activity into a fragment?" -- we have no way of answering that. "Or is there completely different way to embed the whole activity into a tab?" -- no. – CommonsWare Mar 21 '18 at 22:17
  • Why do you have no way of answering that? Btw what I meant is that "if it is possible to convert such an activity (which does not extend Fragment) into a fragment without modifying the whole code and turning it into a fragment". Then, maybe it is possible to turn the activity into a fragment by changing the code. – Xfce4 Mar 21 '18 at 22:40
  • 1
    "Why do you have no way of answering that?" -- you indicate that "SomeProjectClass already extends another class which is not Fragment". That leaves open quite a few possibilities. Perhaps you are using some third-party SDK which only supports SomeProjectClass extending one of their classes, which happens to extend `Activity`. In that case, you're screwed. In the abstract, ignoring potential conflicts like that one, any activity should be able to be converted into a fragment. – CommonsWare Mar 21 '18 at 22:42
  • So this `Activity` can't be turned into fragment? – Xfce4 Mar 21 '18 at 22:52
  • I have no idea. Your question provides virtually no information about this class. If it is extending `Activity`, `FragmentActivity`, or `AppCompatActivity`, then most likely it can be converted into a fragment. – CommonsWare Mar 21 '18 at 22:55
  • It is like an extend chain. SomeProjectClass extends SomeOtherProjectClass. Then when you go to the decleration of SomeOtherProjectClass; SomeOtherProjectClass extends SomeOt...2 and so on. Finally; SeventhProjectClass extends `AppCompatActivity` (or `Activity`). Btw, since these are activities, is it not expected to have them ultimately be dependent on `Activity`? – Xfce4 Mar 21 '18 at 23:03
  • "Btw, since these are activities, is it not expected to have them ultimately be dependent on Activity?" -- yes. However, nobody but you knows what this code is. For all I know, you do not control `SeventhProjectClass` and have no way of modifying it. My guess is that this entire hierarchy would need to become a hierarchy of fragments, rather than of activities. – CommonsWare Mar 21 '18 at 23:07
  • I should study theory about fragments first. Thank you for your time. – Xfce4 Mar 21 '18 at 23:14

0 Answers0