i have a gles based game that takes quite some time to load because of the huge amount of textures.
now i want to display a loading-text or loading-bar as soon as possible as the application is starting up.
what is the fastest way to display a text like this? should i do it in gles as well or should i use an alert or view?
I made a separate loading screen activity in my game that uses the standard Android UI. It has a text view saying "Loading" and a ProgressBar that gets incremented as it loads in images, sounds, etc. from disk into memory (I put all filenames into a stack and then pop them off one at a time and increment the ProgressBar after I pop something off the stack). When the loading is done, it takes the user to a main menu activity, and from there they can start my game.
Related
i have an appwidget which starts an activity as user clicks it.
In my Activity i have a gridview containing relatively small Drawables(Images, because drawable could be mor than just Images) but user can size them.
I noticed that it takes too Long to size them at runtime when Scrolling trough the gridview.
I want to prepare an lruCache only one time in my appWidget's onUpdate which is called at the very beginning when the user places the appwidget on the Screen.
The problem
When i define an lruCache in my appWidget with
private final int lruCacheSize = (int) (Runtime.getRuntime().maxMemory()/1024);
private LruCache<String, BitmapDrawable> myLruCache;
...
myLruCache = new LruCache<String, BitmapDrawable>(lruCacheSize) {
#Override
protected int sizeOf(String key, BitmapDrawable value) {
// TODO Auto-generated method stub
return super.sizeOf(key, value);
}
};
Will it only exist as Long as the process exist of the appWidget? Or does the Cache-File from lruCache stays in my cacheDir of my app? Or will it be deleted after the process of the appWidget is finished? If it does exist over the process-lifetime of my appWidget, how can i Access it from my Activity?
I don't want to create everytime the user clicks on the appWidget a LruCache and fill it up with all the relatively small Images the gridview will Need later. I want to do it once, or if user clears the Cache which will be checked every hour(to save battery).
The Question
How can i achieve that? Or is there a much better/ simpler way.
Time is not really (if it happens once at the very beginning) the Problem, i notify the user that the Cache is being prepared when placing the appWidget on the Screen.
Any help is appreciated.
Update regarding CommonsWare answere
Use Traceview to determine specifically why your implementation is slow.
The app Scrolling is slow because i provide three sizes (small, medium, large) and i scale them at while Scrolling trough my gridview.(Because it would take several seconds to scale them once at activity Startup, so i don't want that).
See here what i do in my imageview which will later Show the drawable(which is an appIcon):
android:scaleType="fitXY"
android:adjustViewBounds="true"
This causes the lag because i do this for everyimage depending if selected scale size is small medium or large.
There is no "Cache-File" in your code.
So then i i'm misunderstanding something. Doesn't the lruCache create an Cache-File in the Cache-Directory of my application? If not how does in works?
First, you cannot force the user to install the app widget. Work on solving the actual performance problem, rather than trying to build some optimization that will not help all users.
My "app" is only an appwidget. There is not appIcon like at FaceBook. It is only an appWidget when he doenloads my app. Which starts an activity when you click on the button.
Second, your process can readily be terminated milliseconds after onUpdate() completes. Do not fill a cache, only to have it never be used.
I want to use the Cache which i want to fill with the Drawables in the onUpdate of the appWidget, and then i want to use These Drawables from the Cache in my activity. So i don't understand why i never would use the Cache? Maybe i'm misunderstanding something.
Picasso would give you better performance from the user's standpoint.
Does it fit my Needs after the update right now?
---------------------------------------------------------------------------------------------
Update 2
Since the scaling should be done by the GPU and take microseconds, I have difficulty believing that is your problem. What specifically did Traceview show you that made you think that scaling has something to do with this?
I noticed that the Scrolling is very fluid at medium size because that's nearly the origin size of the appIcon from the PackageManager. If scroll trough large, where only 2 or 3 appIcons are displayed per row (at medium there are 5 or 6 displayed but it is much more fluid)m it lags. (With the same logic behind it). So the only Logical answere can be scaling in the XML at the ImageView. As i commented that XML-Scaling out and scaled the appIcons to the size Large and put them directly scalled to to my Adapter for GridView it runs really smooth( Only one or to really small lags at the beginning because convertView is null??)
onUpdate() will be called much more frequently than the user will actually use your app widget.
That's right after every onclick or at the specified time. But i check if the Cache has been cleared or not, if not don't Change anything, if so load Drawables to Cache.
I noticed that it takes too Long to size them at runtime when Scrolling trough the gridview.
Use Traceview to determine specifically why your implementation is slow.
Will it only exist as Long as the process exist of the appWidget?
It will only exist for the lifetime of the process of your app.
Or does the Cache-File from lruCache stays in my cacheDir of my app?
There is no "Cache-File" in your code.
I don't want to create everytime the user clicks on the appWidget a LruCache and fill it up with all the relatively small Images the gridview will Need later. I want to do it once, or if user clears the Cache which will be checked every hour(to save battery).
First, you cannot force the user to install the app widget. Work on solving the actual performance problem, rather than trying to build some optimization that will not help all users.
Second, your process can readily be terminated milliseconds after onUpdate() completes. Do not fill a cache, only to have it never be used.
Or is there a much better/ simpler way.
Use Traceview to determine exactly where your problem lies. Then, solve that problem. For example, the problem could be that you are loading these images on the main application thread, and using a library like Picasso would give you better performance from the user's standpoint.
The app Scrolling is slow because i provide three sizes (small, medium, large) and i scale them at while Scrolling trough my gridview
Since the scaling should be done by the GPU and take microseconds, I have difficulty believing that is your problem. What specifically did Traceview show you that made you think that scaling has something to do with this?
Doesn't the lruCache create an Cache-File in the Cache-Directory of my application?
No.
If not how does in works?
It is an in-memory cache.
So i don't understand why i never would use the Cache?
onUpdate() will be called much more frequently than the user will actually use your app widget.
I'm working on an app that can be used for taking notes, simply a drawing application which is keeping bunch of Bitmap objects. I completed creating those pages(Bitmap) and drawing part but i have trouble with memory management, i dynamically create Bitmap object as full screen (for ex; 1280x720) resolution then working on it.
Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
When user starts to create new pages, normally memory keeps growing. Some point i'm getting "Out of memory" error then my application is crashing.
In my application user can navigate between pages with scrolling and can see maximum two pages at a time (partial pages). I wonder if there any existing API for saving those Bitmap objects which is not displayed at that moment and unload from memory and loading those Bitmap objects when need to display. If there is no existing API can you give me some ideas how can i write my own Memory manager, how i must save those Bitmaps and where ?
For example ; User start to create new pages 1-2-3-4 right now i just need show page4 on the screen i don't need to keep page1-2 (page3 could be in memory for smooth transition ?) in memory i need to save it to disk (or encode as PNG ? or any better solution ? ) When user start to scrolling up that means i need to show page3-page4 at the same time (Maybe i also need to load page2 at this moment to Memory for smooth scrolling), so my app works as like that.
You should use multi threading methods and associate them with async task. Take a look here https://developer.android.com/training/multiple-threads/run-code.html
I need some help,
I am creating an app, and want it to run faster I mean when the app is started first it shows a blank white screen for o 1-2 seconds and then loads images. I have a layout background image, and 4 imageviews which are clickable and take you to the next activity. I read somewhere i should use threads to load images and it will load them on a separate thread faster, but i have some problem using it.
So here are the problems and android studio explanations:
Thread thread=new Thread(
public void run(){
ImageView tipka=(ImageView)findViewById(R.id.tipkaproba);
tipka.setImageResource(R.drawable.instructions);
LinearLayout asd=(LinearLayout)findViewById(R.id.layoutproba);
asd.setBackgroundResource(R.drawable.backfround123);
}
).start();
Now the android studio says:
After
"Thread(" )expected
Before
"public void run(){"
; expected
On ").start();"
Invalid method declaration; return type required, Missing method body, or declare abstract.
Now i would like to know:
Does this speed up loading images, ( if not how to do it then)
How to fix my errors.
Thanks anyway !
Do all images fit in the screen?! If users need to scroll to view other images why load all of them at once? Use a grid view with adapter to load the image. In this way when the app start only images on the screen will be loaded and then when the user scrolls other images show up!
another thing you can do is to have 2 version of each image. one low quality with small size that loads first and one for high quality image. that will load latter. You can also calculate the base color for each image (use open source code or do it manually). then set the background image of iamgeview to this color. So when the image finally loads on the screen. The difference is not as dramatic as it was before.
If you want to use thread try AsyncTask first. Using AsyncTask is simpler than defining thread yourself.
Try to decrease the size of your images! If you be able to do this. it works better than any other trick! It's mobile, you don't have to show supper high quality images. users don't even notice most of the time
You probably took care of this but it worth mentioning that you need to provide different images for different screen densities and it's critical for performance as well as quality.
I'm creating a 2d game and i'm using a class with static Texture elements for accessing them from everywhere.Now i want to load my assets asynchronously because i want to show a progress bar with a loading screen.How can i perform this?
Take a look at AsyncTask.
In fact, Google published an article almost exactly what you are trying to do: loading an image in background and display a progress bar while the image is being loaded. The different is, while your code will load stuffs from app resource, the code in google article loads images from network. However, it should point you to the right direction.
See the article at https://sites.google.com/site/androidhowto/how-to-1/create-a-custom-progress-bar-using-asynctask
Note that the code in that article doesn't handle screen rotation well. The problem is, by default, when the screen is rotated, the original is destroyed and the new one is created. If your AsyncTask keeps the any reference to the original one (for example, the one that point to the progress bar object), then it becomes dangling. However, since your app is a game I assume its orientation is fixed, so you might not have to worry about it.
In android mobile we have an default application Market, under submenu there is functionality called all applications. In this, first it shows only ten records in which it will display defalut image and text, then in back ground it will update images. When we scroll down (i.e., end of list) and it shows loading and then it loads next 10, images will load lazily.
How to acheive this senario.
Thanks in Adavance
Jayanth
In this, first it shows only ten
records in which it will display
defalut image and text, then in back
ground it will update images.
I have done this with my ThumbnailAdapter, though I want to rewrite it sometime in the next few months.
When we scroll down (i.e., end of
list) and it shows loading and then it
loads next 10, images will load
lazily.
I have done this with my EndlessAdapter.
Perhaps these will give you some ideas.