I'm rebuilding a set of objects so I can reuse them in other applications. These objects are not activities and only have a set of practical functions that I want to call at any point in the execution of an activity.
How can I have a onCreate
method on these objects without having to extends Activity
?
This code gives error:
public class Session {
Context mContext;
SharedPreferences prefs;
SharedPreferences.Editor prefs_editor;
public Session(Context context){
this.mContext = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
prefs_editor = prefs.edit();
}
public Boolean is_user_logged(){
return prefs.getString("login", "").equals("true");
}
}
But if I put extends Activity
and start executing correctly.
Is there any kind of onCreate
where I can do my initializations for my object without having to depend on the Activity
class?
UPDATE
The error it gives is as follows:
Error:(19, 5) error: method does not override or implement a method from a supertype
Error:(21, 14) error: cannot find symbol method onCreate(Bundle)