I am developing an Android app. I have already crossed more than 20 Activities. So I am bit concerned about it. I mean if there are more Activities in an Android app, does it affect the performance of App like Speed, Memory or any other issue?
Though it is not a standard question but still I feel its something which might help others too
Yes Suraj more activities will affect performance
An activity is the equivalent of a Frame/Window in GUI toolkits. It takes up the entire drawable area of the screen (minus the status and title bars on top). Activities are meant to display the UI and get input from the user
An Activity (calling-Activity) can spawn another Activity (sub-Activity) in 2 ways:
Fire and forget – create an event (Intent) and fire it
Async callback – create an event (Intent), fire it, and wait for it’s response in a callback method (of the calling-Activity).
So the effect of activities will depend on performance of your device, its processor and memory etc.
Even if any activity will remain in stack and not finish then it affects device performance.
Even you have to take a look at security measures.
Related
I am trying to create a TV back light controller that runs on Android TV. To do this I want to use what is being displayed and adjust the back light colors accordingly. I am having trouble determining a good way to basically get a screenshot regularly through a service. Does anyone have any ideas?
On Android 5.0+, you can use the media projection APIs for this. However:
The user has to authorize this, by launching one of your activities which then displays a system-supplied authorization dialog
That authorization does not last forever, but only for however long your process is around (and possibly less than that, though so far in my testing it seems to last as long as the process does)
AFAIK, DRM-protected materials will be blocked from the screenshots, and so using those screenshots to try to detect foreground UI colors may prove unreliable
Is there something like maximum activities in android app?
I would like to know because I am thinking to create sound app with ringtone feature. It will have roughly around 40 activities. But only 1 will be running constantly.
Is that too much? Should I find another way?
Explanation why I need 40 activities
I have 30 sounds and I want to set them as ringtone.
1 normal activity with buttons to play Mp and stuff, and 35 other activities, 1 for each file.
What I want is to on Long click start activity with layout and there will be more buttons
I tried with contextual menu but it doesn't look good.
You shouldn't have a problem directly due to the number of activities, but I question your design. It will likely be difficult to get right and suffer performance issues and the APK will probably be very overly large.
An alternative approach could utilize the fact that you can selectively use/show different layouts for a single activity and that a single layout can selectively show different components in the the same visible space.
You can have as many activities as you want. There is no constraint on the number. All Android activities are stored in a stack and the one at the top of the stack is the one that is visible. When memory is low, the Android OS will automatically start killing the ones that are lower down the stack and are not running any background tasks or services.
I'm working on an app that doesn't support screen rotation. Do I really need to save the instance state of all my activities? How rare is it for android to kill activities? If the activity is killed and restored it will just look to the user as it did when they first came to it, which was probably quite a while ago anyway if the system has killed it. It doesn't seem like such a bad user experience to me if it is rarely going to happen. What do you think?
It is a catastrophic UX if an application loses its state just because I went to the settings to change the screen brightness. This happens frequently on 512MB RAM devices - which are still sold in large quantities. There are even devices with 256MB produced right now.
Yes, it happens a lot. It will happen to certain users much more frequent than to others. Those users will have no pardon with your app.
it really depends on the type of screens you are developing. When the activity contains a lot of data for example, it should be convenient to save the state of your activity (not all activities).
If you have several fields that the user must refill, it can be a bad experience especially if the virtual keyboard of device is not that easy (assume you are using a Galaxy mini for example)
In other words, it is a good practice but its up to you to decide if the user experience will be degraded or not
Serge
FWIW, I have written several single orientation apps for our current product and I feel that it's still important to save state. It just makes for a more usable application when everything is how you left it when you return.
In general, it's not that much work either. First, keep in mind that if you assign an ID to views in your layout's, the default Activity.onSaveInstanceState() will do most of the work. It will remember Checkbox states, EditText contents, etc. There are relatively few things you need to save. Here are some of the things I've saved with the state:
Relevant Activity parameters
ListView position information
Current Tab in TabView
Activity parameters are by far the most common.
I'm wanting to use android:configChanges="orientation|keyboardHidden" for a few of my activities so that my onCreate doesn't get called again, but I thought I'd see if anyone had a list of pros and cons first because this link says that it should only be used as a last resort.
It's weird that Google doesn't really talk more about the reasoning behind it, but there are really three main reasons I can think of to avoid using that approach:
In my experience, some view types (particularly WebViews and MapViews on Android 2.1 or lower) can behave rather oddly after the orientation change if they haven't been recreated (zoom buttons mispositioned, for example).
It prevents you from using orientation-specific layouts (see the new Market app's landscape view, for example).
It can keep you from discovering buggy behavior from your application relating to other types of reasons your Activity might be destroyed and recreated (e.g. low-memory or other normal kills while backgrounded). That is, if your activity can gracefully handle a restart due to rotation, it can probably handle a restart due to background-killing. If you skip handling rotation, though, you may not encounter a restart due to background-killing under normal testing until a user with an older low-memory phone writes in with a bug report.
The last reason is the big one; especially with older low-RAM phones and with the supposedly more-aggressive autokilling behaviors in Gingerbread, your activities need to know how to quickly be recreated after a destruction by saving their state, regardless of orientation handling. And once your activities can handle those kinds of destruction/recreation, you're probably all set for rotation change kills anyways. You can gain some speed by absorbing the rotation event (since you don't have to go back through layout inflation and all that) but that's about all, at that point.
If you do decide to swallow rotations I highly recommend always using an emulator or device with the Development.apk's "Immediately destroy activities" option checked, and then making sure that switching apps or backing through your task stack still work correctly.
In my experience absorbing rotations can actually a good choice for an improved user experience, especially on activities with complex layouts that may take a few moments to recreate, but you really need to test carefully and effectively make sure that your activity would still work even without the rotation-ignoring.
A big Pro of using this approach is that it requires very little effort on your part, and that your app will survive config changes without resorting to crashes.
The small drawback is that using configuration specific resources (for landscape or portrait orientation) don't get applied automatically.
In my (perhaps little) experience, I think its not really worth the effort to do all the plumbing.
"Proper" handling of these config changes requires a lot of plumbing on your part, and things get even more dramatic if you have to support progress dialogs during screen orientation changes.
Although most people will opt for the quick fix by changing the manifest, and configuring their activity with android:configChanges=”keyboardHidden|orientation”, I think it’s important to realize that there are alternatives to this.
It requires more code, but it does give you better insight in how the overall system works.
I opened my application after I am not doing any kind of operation. I leave the mobile 5 min. After 5 min when I touch the my application it is showing black screen. Is there any way to avoid this idle state?
This is easy to do. Use: getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); in your onCreate method.
There is another way, called a WakeLock, but you really shouldn't use that unless you know what you're doing. See this post from one of the Android designers for more information about WakeLocks and why you shouldn't use them unless you're careful.