-1

I'm wondering if it's possible to use onResume() and onPause() outside the MainActivity. In my android project, I have the typical setup for my main class

package com.my.package
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
       // blah blah
    }
}

I have a second class in the project which extends the MainActivity, but my onResume() and onPause() never run

package com.my.package
public class OtherClass extends MainActivity {
    @Override
    protected void onResume() {
       super.onResume();
       // resume code
    }

    @Override
    protected void onPause() {
        super.onResume();
        // pause code
    }
}

Is this possible? Am I doing something wrong? I'm trying to organize my code because my MainActivity file is getting too large. thanks in advance.

newbie 14
  • 3
  • 2

1 Answers1

0

If other class is supposed to be an Activity, then yes you can create an Activity class hierarchy just like anything else. Its not uncommon to have a base Activity class for an app that other activities derive from. But the only place you should ever call onPause or onResume from directly is from a derived class in their onPause/onResume- otherwise you could screw up the framework in interesting ways.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127