Android - Using ActionBarSherlock along with ORMLite - android

I have a parent Activity that ALL other activities in my app extend from, let's call it MainActivity. At first it was extending OrmLiteBaseActivity, like so :
public class MainActivity extends OrmLiteBaseActivity<DatabaseHelper>
Now that I want to use ActionBarSherlock in my app, I have to extend from SherlockActivity... But I can't extend from two classes at once.
Has anybody worked with ORMLite and ActionBarSherlock before ?

As said by PratikButani: I ended up using ORMLite's OpenHelperManager for each time I wanted to used the database.
Link : https://stackoverflow.com/a/7662537/1318946

Related

Android Class Diagram UML

I'm trying to create a class diagram for an android project.
I want my classes represent the activities, services and interfaces that I will implement.
There are several questions about it on the web, but I couldn't find a definitive answer.
I know that there aren't specific rules for Android and UML, but I have some doubts.
How can I represent the relationship between an Activity and a AsyncTask ?
How can I indicate that an Activity has an intent to another Activity ?
Maybe if someone has an example, will really help.
Maybe something like this?
MyBackgroundTask IS A AsyncTask
MyActivity IS A Activity
MyActivity HAS ONE MyBackgroundTask
You can use a dependency to show that there is an relationship between the AnActivity class and the AnotherActivity class:
In this case, it means that the AnActivity class requires the AnotherActivity class for its specification or implementation. Also, use notes to make it clear.
Update:
Another example:
MainActivity IS A FragmentActivity
MainActivity HAS SOME fragments. The fragments are of type String.

Adding functionality to the activity (inheritance, decoration, strategy ... )

I cannot decide what approach should I use in the next situtation.
One activity from my app need to have different functionality, here is the leak of multiple inheritence comes into play.
What I need to get ?
There are several parts that my activity has to have.
Navigation drawer. I am using MaterialDrawer library. It requires activity to implement on click callbacks (or use composition instead), but also it use activity as constructor argument,so I think it will be better to put this into separate class inherited from Activity or any base class provided by Android Framework . Thanks to library developer it doesn't require any stuff to be done in on create method ( setContentLayout for instance)
My activity(one of several) will have only Toolbar and FrameLayout for holding fragment . Or it is better to separate toolbar and single fragment ?
This in turn requires some stuff to be done in onCreate : setContentLayout with basic layout , add fragment to the container set activity actionbar .....
Maybe in future I will use another libraries that requires to add something in activity lifecycle methods.
All these points in order to follow Single Responsibility principle have to be separate classes inherited from some base Activity.
For example we will have something like this.
public class SingleFragmentActivity<T extends Fragment> extends AppCompatActivity {
}
public class SingleFragmentToolbarActivity<T extends Fragment> extends AppCompatActivity {
}
public class NavigationDrawerActivity extends AppCompatActivity {
}
....
As you can see each functionality is put into the separate class, but what if I need to have SingleFramgentActivity with NavigationDrawer ?
In this case I have to inherit one of these classes from another, for example
public class NavigationDrawer extends SingleFragmentActivity {
}
If to do so, I have no ability to use navigation drawer separately from SingleFragmentActivity.
What is the best practice to follow in this case, how to build class hierarchy to make it flexible and use Open-Close principle, to make changes in application without any pain. (Use strategy, decorator ..... ?)
I would be grateful everyone for help.

How do I extend two classes

I have this android application and I am trying to extend two classes at the same time. I have this code:
public class TimelineFragment extends Fragment {
public class TimelineFragment extends Activity {
//all codes here
}
}
On my second TimelineFragment, it has an error that says: The nested type TimelineFragment cannot hide an enclosing type
I have this android application and I am trying to extend two classes at the same time
That is not possible. Java does not support multiple inheritance.
I have this code
Given your class name is TimelineFragment, one presumes that it should extend Fragment. Whatever problem you are trying to solve via multiple inheritance will need to be solved in some other way. For example, if you are trying to perform operations on the activity that hosts your fragment, you can call getActivity() from the fragment.
Multiple inharitance is not possible in Java, and therefore in Android.
multiple inheritance is not possible in java so therefore u cant't use it in android as well.
Well one thing you can do is to create interfaces instead of class and implement any no. of interfaces you want and their methods.

Share Same code in Activity and ListActivity

My project consists of couple of activity and ListActivity items, there is some common piece of code(Navigation bar and some other codes) which needs to be done on both type of activity.
Is there a way I extend the activity and write my piece of code, and let ListActivity also inherent that code ?
right now I am copying the same piece of code in two classes , one is Activity extended and other is ListActivity extended
You could also have the common code in a class CSuperCommon, and have each of your Activities contain an inner class that inherits from CSuperCommon. Some initialization will need to be done such as setting the parent view, context, etc.
There is no real multi inheritance in java (and so in android) but it is possible to simulate it: http://www.javaworld.com/javaworld/jw-10-2005/jw-1024-multiple.html.
Here is another answer from stackoverflow: How do Java Interfaces simulate multiple inheritance?
Have both extend a Base Activity class (which will have your common code) and implement a list view in one of them. Implementing a list view is very easy!

Android: Using methods from an Activity in a Widget. Extend Activity and AppWidgetProvider?

I'm working on an Android app which has an activity and a widget. This is currently implemented via two classes in two .java files - one for the activity (extending Activity), one for the widget (extending AppWidgetProvider). Nothing out of the ordinary here as far as I'm aware...
However, the widget class code could be a lot simpler if it was to make use of functions and asynctasks defined in the activity class. Duplicating these functions seems like bad design, so I'm wondering how I can structure the app to make them usable?
Can I extend both Activity and AppWidgetProvider somehow? Can I import one in the other?
Thanks!
either make the funcs static, or make a 3rd class to hold these funcs
Move the functions down into a service. Create a Service and you can use context.startService(Intent) from you WigetProvider or from the activity to access the functions.

Categories

Resources