Reputation: 41
Have some problem with android finish() methods. I have one parent-class activity. Lets call it ParentActivity. All other activities in my project extends ParentActivity. Each time on ParentActivity.onCreate there are some statement, and I want to stop activity from executing if it fails. But when I call finish() in parent, I cant stop executing onCreate method on its child. Something like that:
public class ParentActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!someStatement) finish();
}
public class Test extends ParentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("TAG", "I dont want this code!");
}
}
Surely, I can just verify in parent activity its status each time, but I dont think its a good idea.
public class Test extends RexActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isFinishing()) return; /// It works - but it bad :(((
Log.d("TAG", "I dont want this code!");
}
}
Can I somehow stop executing onCreate method on child activity from its parent? Many thanks for any help!
Upvotes: 1
Views: 161
Reputation: 4841
I'm not sure if I got your question right. As you have some grammatical issues.
onCreate
statements are always executed. You can either have a Boolean
in ParentActivity
to stop the code from executing in ChildActivity#onCreate()
.onCreate()
code more modular by dividing it into functions so that it's not called.Let me know what works for you.
Upvotes: 1
Reputation: 3873
Best option is to Use finish() in your splash screen just before you create your second activity,
Upvotes: 0