Android :: Is There A Design Pattern To Cut Down On Code Duplication When Subclassing Activities?
Apr 6, 2010
I've got a common task that I do with some Activities - downloading data then displaying it. I've got the downloading part down pat; it is, of course, a little tricky due to the possibility of the user changing the orientation or cancelling the Activity before the download is complete, but the code is there. There is enough code handling these cases such that I don't want to have to copy/paste it to each Activity I have, so I thought to create an abstract subclass Activity itself such that it handles a single background download which then launches a method which fills the page with data.
This all works. The issue is that, due to single inheritance, I am forced to recreate the exact same class for any other type of Activity - for example, I use Activity, ListActivity and MapActivity. To use the same technique for all three requires three duplicate classes, except each extends a different Activity.
Is there a design pattern that can cut down on the code duplication? As it stands, I have saved much duplication already, but it pains me to see the exact same code in three classes just so that they each subclass a different type of Activity.
Edit: Since it seems I need to be a bit more specific...
Suppose I'm trying to solve the problem of an AsyncTask background download during orientation changes. The solution I have right now is to use callbacks; there's download manager that I have which starts these downloads, and then I have the Activity attach a callback to it. When the orientation changes the Activity is destroyed and then recreated; during this process I detach the old Activity's callback, then attach a new callback from the new Activity afterwards.
Orientation changes are a common problem, and in multiple Activities I start the Activity with a progress view while the data loads. What I am trying to solve is not having to re-implement this orientation-handling logic ten times over; my initial solution was to subclass Activity, but then I got the problem above.
View 4 Replies
Apr 28, 2010
While programming on Android, I end up writing a parent activity which is extended by several others. A bit like ListActivity. My parent activity extends Activity. if I intend to use a Map or a List, I can't use my parent activity as superclass - the child activity can only extend one activity obviously. As such I end up writing my parent activities with the same logic for Activity, ListActivity, MapActivity and so forth.
What am I looking for is some sort of trait functionality/design pattern which would help in this case. Any suggestions?
View 3 Replies
View Related
Feb 23, 2010
Does the Android platform lend itself well to a particular style of UI programming like MVC or MVP? Most of my UI experience is with spaghetti code on a very old embedded device or in GWT with MVP so I do not know where to start.
View 3 Replies
View Related
Aug 23, 2010
I fight with me for some days about asking this question.
Its pretty plain and simple:
If you have an application with a GUI totally working on 2D drawing, what should be the best practice to handle what to draw and where to touch?!
Some example for better understanding:
I have a game with a map. On this map I can build houses and stuff.
I also have a information bar which can be extended. On the extended bar I draw some information about the game and also enables to change different values. If a touch occurs, I have to check, if the information bar is extended or not to determine if I want to change something on the map or something on the bar.
Thats done by the State Pattern, but I have some doubt if thats the right one because I think it can be a bit complex because of possible "sub-states".
So basically the question: Is the State Pattern (from GoF) the best practice to handle a pure graphical GUI?
View 1 Replies
View Related
Oct 29, 2010
I have several related database tables and I would like to treat their rows as objects and their tables as something like lists. What are the considerations that I have to keep in mind (for instance, ensuring that the objects stay consistent with one another and with the database, lazy loading)? And what is a good design pattern for implementing this? As I imaging the answer is pretty involved, a link to a good website would suffice.
On the other hand, if someone knows of Hibernate-like thing that really works on Android, I might give that a whirl (although it's a little heavy weight for me right now).
View 2 Replies
View Related
Nov 22, 2010
I am designing an app that will have some activities separated in tabs. Some of them will have to perform tasks in the background will the user is in another tab. What is the best strategy for designing an app like this? I was thinking about using a service but it can be killed by android dalvik, isnt it?
View 1 Replies
View Related
Oct 8, 2009
Is anyone aware of an example or sample code that shows how to make a settings page (like what you get from hitting settings)? Many apps seem to have them but I'm not sure what type of list they are using.
View 4 Replies
View Related
Sep 6, 2010
As i am building multiple activities, i realise that i have to code out repetitively this segment.
CODE:.......
So that i can return to the home page.
Is there some structural pattern or design pattern that i am missing out? Like a Activities Manager that manage all the activities?
View 8 Replies
View Related
Sep 18, 2010
Basically, we are maintaining the sessions for the specific user's environment. For that, Three basic stuff we have to maintain. That are Login, Session check and Logout.
In Android, Each screen designed by Activity. we can startActivity() and finish() a current Activity. But you can not do that Previous Activity.
UI Design of APP:
Login(Main Activity)-->Home(Child Activity)-->It contains Profile, add data, settings,etc.(Sub Child Activity). All Screen has a Logout option in Menu.
The Problem is:
When i select a Logout. The App gets Logout. But I can not navigate the App to the Login Screen. The Previous child Activity did not finished from the Activity Stack.
View 1 Replies
View Related
Oct 7, 2009
I have an app with two activities.
Both activities among other functions have to perform the same calculation on data, so each activity include the same code to perform the calculation.
Is it possible to only have the similar code in a separate activity and be accessed by the other two activities instead of duplicating the code twice?
View 15 Replies
View Related
Jul 2, 2010
I have an Android application composed by several Activities. Most of them need to check whether an active network is available or not:
public boolean isNetworkAvailable() {
ConnectivityManager cm = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
TelephonyManager tm = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
...
}
I would like to move that code to a helper class in order to avoid the need to write that code in every Activity, but calls to getSystemService are only allowed from an Activity. The other alternative is to move that code to a parent activity use inheritance but:
Every activity already extends from android.app.Activity
Some of my activities already extend from a common my.package.BaseActivity
(Activity <- BaseActivity <- XXXActivity)
What do you recommend in this case? Is there any other alternative?
View 1 Replies
View Related
Jul 15, 2010
Are Activities in the background considered "running" (and can execute code) or are they in a suspended state?
View 1 Replies
View Related
Jun 8, 2010
I provide a small tool called PatternControl via the market that give the users the opportunity to temporary deactivate the Android "lock pattern" for a definable amount of time. With other words: After entering the pattern, the pattern becomes deactivated for i.e. 5mins and re activates it self afterwards. Until now (Android < 2.2) this was only possible by changing the settings directly, because there was no related API provided. (i.e.with something like set Boolean (Settings .System.LOCK_PATTERN_ENABLED, enabled)) It is clear that this in not a good way, but from my knowledge there was no alternative. My hope was, that Froyo would introduce a new API to handle things like that "legally". With the new security model of Android 2.2 writing to this kind of settings is now disallowed and the PolicyManager class seems just to offer password complexity options. So here is my question: Is there still any way to temporary deactivate the "lock pattern" as long as Android does not support such a delay functions natively?
View 25 Replies
View Related
Aug 26, 2010
First, let me fully admit this is an annoyance to me. Second, let me fully admit this situation is 'as designed.' As was indicated by Verizon, FRG22D made some changes that 'improved security.' In particular the ability for Exchange admins to enforce security settings. Well, I have a hosted Exchange account (personal email) with 1&1. Post manual update to FRG22D, I am now required to have a PIN code to unlock the phone. No unlock code and the pattern are not available. So, every time my phone comes out of 'sleep' mode, I have to enter my PIN. Incredibly annoying...
Ultimately, it's an issue to work out with 1&1 to see if this can be changed. I see no setting in the options presented to me in the OWA settings or in 1&1's XAdmin panel. If anyone happens to know if this is easily changed... please let me know. Sorry for the partial rant, but I am incredibly annoyed.
View 16 Replies
View Related
Jan 23, 2014
My phone is a maguro (Galaxy Nexus GSM), bootloader unlocked , ClockworkMod Recovery and Cyanogenmod11.
I found online several method to delete the code/pattern security.
Some methods use USB debugging (I have a Tasker script that disables it at every boot).
I also found a clever and powerful tool that really scares me. There is a zip that deletes the Gesture.key and Password.key file.Are there other methods from which I should protect my phone and my data?
View 3 Replies
View Related
Oct 3, 2010
I am writing a game for Android and I think I have a fatal flaw in my architecture and/or code. The architecture is basically two threads, one that just continuously draws the screen and the other than controls the movement of the drawables on the screen based on the user's touch screen input. In the latter thread, I'm basically doing manual animation (insert correct term here), meaning I move the drawables on the screen via methods that change the Drawables Rect as the game progresses. The "no-no" I believe I'm doing is inserting delays into these methods, so that it "appears like an actual animation." This all works fine and dandy because I have no reason to process any user input during these animations, but it's really bugging me that I'm designing a flaw into a lot of hard work with my game. I'm sure many of you can relate to this in terms of code design.
View 3 Replies
View Related
Sep 5, 2010
Just brought a I9000 yesterday and have already forgotten my pattern code and never set up a gmail account, tried all the hard reset keys but doesn't work. Has anyone figured it out how to hard reset it properly or update the firmware without kies? As kies doesn't detect my phone.
View 1 Replies
View Related
Nov 3, 2010
Often, a simple of ArrayAdapter does what I want and during early development I will provide the android.R.simple_list_item_1 for the view id required by the ArrayAdapter constructor. Is it possible to provide a customized view which is based on the android.R.simple_list_item_1 to the ArrayAdapter constructor?
I do not fully understand Android's 'include' functionality, but what I would like to do is something like:
Define a new TextView based on customizing the android.R.simple_list_item_1.
(I have no idea what the valid syntax would be)
code...
Reference my customized TextView. I assume that something like this would go into my layout directory. Then in my code I would do something like:
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.id.MyTextView, null);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, view.getId(), myArrayOfData);
Is this possible and if it is, what is the appropriate syntax to accomplish what I want?
View 1 Replies
View Related
Nov 4, 2010
I've been scouring throug the examples and tutorials but I can't seem to get my head around how to handle recycling within a subclassed SimpleCursorAdapter. I know that for regular ArrayAdapters you can check convertView for null and inflate if null from the xml and if not null, recycle, but I'm having a little trouble visualizing how that works with the from and to arrays within the SimpleCursorAdapter subclass. I tried to figure this out from the The Busy Coders Guide to Android Development by Commonsware but was unsuccessful. If anyone knows of any tips, examples, or tutorials, I would be grateful to see them.
View 2 Replies
View Related
Nov 26, 2009
This was pointed out earlier by someone on a thread and I couldn't seem to find it. But just to point it out again the moment can be turned off or put on airplane mode even while its locked. This may be a bad thing if someone steals your phone and you want to use someones phone to either call or text it so that it will ring to find out who has it. All the thief has to do is put it on airplane mode or turn it off to deactivate ringers, sound, and gps.
Is there an app or option where I can use a passcode to unlock the phone rather than the pattern?And is there a way to track my phone through gps just in case it's lost or stolen?Any ideas or suggestions if a device someone rely relies on a lot is lost or stolen? My friend on his moment was able to add a message on the home screen saying "If found please contact "phone number" "email" and will be given a "$300" reward.
View 4 Replies
View Related
Aug 10, 2010
New to Android and new to this forum. I've converted from a blackberry and I can't tell you how much I love my Captivate. Well, enough of that :-) I have a few questions. I currently have my display set to time out after one minute. When I'm using the music player is there anyway to prevent the screen from locking. I have having to unlock it to switch tracks.
As a side, is there a way to change the locking system from a sliding pattern to a number code?
View 3 Replies
View Related
May 3, 2010
I think the title says it all, don't you? It should be possible to create a new contact App by duplicating an existing one, either in GMail Contacts (in a full-fledged browser) or directly in the Contacts app on an Android device. This would allow, for example, adding new members of a family or new employees of a company. Then, just the new name, email or phone number (or whatever) could be entered to replace the duplicated ones and leave the remaining fields all the same. As a former Palm user, I was able to do this on that platform (primitive as it now seems by comparison to Android).
View 7 Replies
View Related
Jul 27, 2010
I have 2 android applications that share 95% of their resources, layouts, strings etc. only a few jpg's are different.
How can I share resources between the different Eclipse Android projects, so as to avoid resource duplication ?
View 2 Replies
View Related
Apr 27, 2010
I have had my Hero for about 4 months now, and up until this week everything has been fine.I noticed at the beginning of this week that the People App has started to show my contacts in duplicate. This is happening to every contact. I don't have any actual duplicates saved in my contact list, it's just listing them twice in the app.I have checked and double checked that I don't have contacts listed as both Google and Phone, all my contacts are Google.I have checked on a desktop browser in my Google contacts and I don't have any duplicates saved.To note: This is only happening in the People App, there are no duplicates when I go to the "Phone" menu, and there are no duplicates when I use the People Widget or Live Folder Widget.It's a minor problem, but one that I hope somebody can help me with.
View 8 Replies
View Related
Mar 16, 2013
upgrading sd card from 8 to 16 gb. when copying from one sd card to another there is still 5 mb of uncopied files? first made sure the show hidden files was checked, tried a couple progs and to no avail all say directories are the same? is the additional data a swap file or a program.
View 5 Replies
View Related
Nov 23, 2010
I am going to develop an Android Application but before developing it i needs to have MockUp for the Android Application,so is there any way to design MockUp/GUI Design tool for the Android Application?
I know about DroidDraw tool , but i think it is not the exact way to prepare Mockup for the android application.
I have already referred this SO Question , but overthere i just found all the tools for the I-Phone only. So please feel free to share with me if you have/found any !
View 3 Replies
View Related
Oct 19, 2011
When receiving text or emails it receives duplications? Where does the problem lay.
View 2 Replies
View Related
May 1, 2010
What happens if I enabled the pattern lock by updating the setting LOCK_PATTERN_ENABLED, but have never set a pattern? I would check, but I don't want to reset my phone (I don't see a way to clear the lock pattern). Does anyone know?
View 3 Replies
View Related
Dec 11, 2009
The subject is pretty much it. With pattern lock security enabled, what happens during an incoming call? Must you enter the pattern to pick up the call, or can you simply press "Send"?
View 2 Replies
View Related
Apr 17, 2010
I hate posting a query about something so seemingly simple. I googled around and can't find a duplication of the icon in the notification area of my new (since January) Eris running 1.5 stock.
I'll describe it: it in most ways resembles a little musical note, perhaps an eighth-note, but with a diagonal slash through it (not in a circle as the "no" sign).
Nothing running in the background, music-wise. On page 47 of the user guide/manual is a list of all stock icons; it is not there. No new apps have been installed for weeks.Any ideas as to what it could be?
View 17 Replies
View Related