I have an app with 3 activities. I noticed there is a slight delay when going from 1 activity to the next (~0.3sec). My Java code is pretty simple, my XML are a little less simple. My XMLs on average contain: 4 TextView, 1 list view and 4 buttons. I removed the animation effect in the manifests xml. But still i notice this 0.3 sec delay between activities. Is there a way to reduce that delay between activities Or my xmls are simply too heavy?
You can try to use the Fragments instead of Activities. You can dynamically show them, without delay, because they will be always loaded in a memory. The delay between Activities start is because the system must at first check intent, for other application that can make this action, and after that create new Activity.
Written a code in Run time for 3 activities and try it.
Related
I want to override the android chronometer class. I want it to inflate a custom XML layout and to also have a quicker update interval.
I've found one that modifies the update interval from the default 1s to 0.1s on github.
But I want to do more and have imageViews or Buttons display the time instead of the default textView it uses. I haven't really done this before except for a recycle view, so some explanation would be nice.
My end goal is to have an efficient stopwatch with custom digits and display, like the one found on HTC one M7 in the default clock app or any Samsung phone. I also need it to run in its own Fragment and be able to handle orientation changes and the activities onPause() or onStop() without losing any time.
Would it be better to use Intent Service and a Results Reciever? if so how would i accomplish this?
Chronometer is good for certain extent, but instead of customizing it you can create your own custom layout and display the time based on your requirements using a handler which would be the best solution for your problem.Find the link below for example
http://www.shawnbe.com/index.php/tutorial/tutorial-3-a-simple-stopwatch-lets-add-the-code/
In my app, there are 2 activities. To make the transition seem smooth I animated elements of the first and second activity and disabled transition between the 2 activities. An example of what happens is in the video below:
https://youtu.be/L85HfIUPQuk
The problem as you might see is that, once the animations in the first activity end, there is a period, less than a second but still noticeable, where the screen hangs on the empty white background. Only after that does the second activity and animations start.
The animations are simple alpha and translate effects, nothing fancy.
Any suggestions how to get rid of the hanging period?
You should use Activity Transition.
I think what you need is Shared Elements Transition, since the list from first screen is also on the second screen. Checkout the documentation:
http://developer.android.com/training/material/animations.html
I'm begining to learn android development, and I'm trying to make an app just to learn the language and philosophy.
This app, has to show an image in the middle of the screen, a button below, and a chronometer in the right side. When the app starts, the chronometer has to begin a countdown. When the user press the button, a blur effect has to be applied to the image, and the seconds left to finish the countdown increase by 10.
I almost know how to program the blur efect to the image, the button press, and the countdown and increase by 10 whenever the button is pressed. But I'm not sure about putting all together.
As far as I know, it should be done by designing an activity, and putting inside the activity the image, the button, and another image or a set of changing images or text for the countdown clock. But as I advance in my studied, today I have read that in order to manage different actions in an activity it is neccesary to do it by using fragments. And I have found much complex programming fragments than activities.
So the question is: can I make what I'm trying to do by a simple activity and defining classes and methods for the image effect and the countdown clock or have I to make it with fragments?
Thank you very much.
today I have read that in order to manage different actions in an activity it is neccesary to do it by using fragments
To be blunt, either you either misunderstood what you read, or you are reading the wrong material.
can I make what I'm trying to do by a simple activity and defining classes and methods for the image effect and the countdown clock
Yes.
have I to make it with fragments?
No. It is possible that the whole UI might be a fragment, particularly if it might be shown alongside something else in some cases (e.g., a tablet) and not in others (e.g., a phone). And there is nothing stopping you from making that UI using several fragments, though that would be rather unusual.
As others have already conveyed, no need to go with fragments.. Activity wud suffice.. As far as putting it together is considered, I guess you need to learn more about layouts.. Layouts are the files which basically help you put things on UI as you want it to look like.. There are plenty of material available online for understanding layouts.. Happy learning.. :)
I'm working on an app where basically i have X different activities but everyone has a layout equals to the rest. To let you understand better let me do an example:
Suppose i have a game where you have to guess 10 words each level, and I have 5 levels, basically I have in every view 10 question.
So is better to have 5 different activities or only one activity and 5 layouts, one for every level ?
Looking around on the web i did not find a good answer, someone told that Android is based on activity, so 10 different ones is the way to go, but was only a guessing, nothing technical.
Don't make 10 Activities. Don't make 5 layouts. All questions look the same except for the text, right? Don't Repeat Yourself.
Simplify your life reuse the same Activity and Layout for every single question.
When you start the activity, you can pass in data using the .putExtra() methods. Use that to pass in the things that change, like the question text, the correct answer, and the current level.
I would do 1 layout and then program the levels onto it.
Doing a brick breaker game, or tetris, or puzzle game wouldnt want you to have a million diff activity options, but more like 1 layout and 1 activity will populate accordingly.
Usually you can do something like
[home] -> {play, options, exit}
[play] -> {new game, level select}
[options] -> ....derp...
[exit] -> ....derp...
[newgame] --> start activityA where level = 1
[level select] -> click a link which will start activityA with a level = selected.
1 activity which will spawn your information safe and nicely... far far better imo.
I'm trying to make an application thats has blinking effect,
e.g. switching back and forth between 2 layouts, one is red and the other is blue for example.
(any layout has diffrent image in it)
When trying to switch fast between 2 activities or 2 fragments the application is crashing.
How can I programmatically change activity layout in a better way?
My personal reservations against blinking aside, you could change just the background color of your root layout with a timer.
You should just change the background color or the layout that is being displayed by the Activity.
Think about efficiency:
If you change layouts android will have to inflate the XML and its widgets and you will have to get handles to all these by querying and layout (ie findViewById). You can think of the first problem of this as refreshing a web page to change the color of an element instead of just rendering dynamically. You can think of the second part of this as not caching DOM handles and having to requery-ing the DOM every time you want to provide and action in JavaScript. Both are bad practice.
Or, you could just change the background of the current layout every X seconds, minutes or whatever you are trying to do. There are many ways to do this - the AlarmManager, or start a Thread with a timeout - or better yea, start a new Thread that will post a runnable back to the main thread to change the background color - then sleep the auxiliary thread for X seconds and repeat the loop.
The second idea is not only good practice - but you are using the SDK framework correctly.
Good Luck!