Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to write a surface View without creating a thread. is it possible to create a surfaceview ,without calling it from thread. if possible, please provide me a simple example.
Your question doesn't entirely make sense to me, but I'll try to answer what I think you're asking.
Yes, you can draw on a SurfaceView without creating a dedicated thread. This is not the recommended approach; you should do your rendering off the main thread so that the app doesn't become slow to respond, but it's not an absolute requirement.
I don't know if it counts as a "simple" example, but Grafika's "multi-surface test" draws on three overlapping SurfaceViews from the UI thread. These are static images, drawn once, so there's not really a need for a separate thread. If you start an animation on one of the surfaces (with the "bounce" button) it kicks off a new thread, because it's just easier to manage that way.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am building an Android app which uses activity and fragments and rest calls and a local database. Does anybody know where REST calls is ideal to be placed. I am more interested for fragments but would also like to know about activities as well. I also have a local SLQLite database and I have a method for getting the data. Because a database operation is long running is that similar to a REST call?
Thank you
You SHOULD NOT place long-running operations or any model logic on classes that can be destroyed by configuration changes (rotations, screen changes, phone states), these classes are designed to render the UI to the user.
You should instead use:
ViewModel (for shorter tasks, will only survive as long as the app does) and use a background thread.
https://developer.android.com/topic/libraries/architecture/viewmodel?gclid=Cj0KCQjw09HzBRDrARIsAG60GP-qiuPnYKryrX2YYZI39988xMfqTx4s6fuk5xfKtvuPZ-XQ98DxpgEaAphmEALw_wcB
Services (Recommended, can survive despite your app not being active), make sure to check out the documentation first and some examples.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need help with my app, I created an app but it runs slowly, i guess because of the background and the images, now i read somwhere i should use threads and a loading screen until all app images are loaded so it runs faster. I dont know how to use threads, could you elp me or at least send me somewhere I can learn how to do it. One more thing i get an error whne i am using Activity extends fragment at loading sql something at getappid or something like that. is there an easy way to fix it? This app is made for android 4.0 - android L
My application can be found at the link below:
https://www.dropbox.com/s/22kchus06l2lf0u/app-release.apk
If you need more info like main xml and main java code i can paste it here...
Thanks anyway !
A very basic example of a Thread:
Thread thread = new Thread(
public void run(){
// Do stuff here
}
).start();
Everything inside the body of run() will be executed separately from the UI thread.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
can you explain why does not allow network access in the main thread of a process in Android?
If anybody can explain. Its will be helpful for me.
Because the main thread is responsible for all the UI (user interface) operations (it is also called the UI thread). Everything related to displaying stuff in the screen is done by it. So if you occupy the main thread with long operations such as a network operation, you will experience jitter in the screen and even ANR errors (Application Not Responding). In more recent versions of Android you will not even be allowed to do that as the application throws NetworkOnMainThreadException.
Till Donut it is used to create multiple threads from 1.6-2.3 that you was using before but if now you are using 3.0 or above then it is used to create single threaded model by using AsyncTask otherwise you ll get the NetworkOnMainThreadException.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm creating a game where I use a custom view.I use onDraw(Canvas canvas) to draw my game with touch listeners.Now that I'm in need of a bitmap to be drawn on the same canvas but running on a different thread,I don't know how to proceed.The thread I create must draw the bitmap for a specific time only.I tried creating another custom view implementing runnable and drawing the bitmap i need.But i dont know where to call it.As I'm new to programming,guide me on how to deal with this idea of mine.Thanks in advance.
I recommend You to follow this order ( and how often to read ? That often, until You understand everything in each topic ).
There we go:
Basics to go :
Process
Thread
Multithreading
Multithreading 2
All about multithreading 1
Original docs about mt ( java )
mt programming java
Basics of android mt programming
I suppose, You now will have much to read.
But keep in mind, You must do it. Threading can bring You in situations, where You almost cen get lost, if one thread hangs up and or blocks some other thread. Therefore You need all the background information, because, once, You are in trouble, You then know, where to look first.
Have fun.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
This question has been bugging me for a while now.
The idea is that I want to use a way to draw/create a view in a fast way.
I read that XML layout has more advantages than a dynamic one.
I read also about caching. Apparently, we cannot/shouldn't cache the whole UI element. If we save its state/value and re-create it, doesn't it take the same time as creating it from scratch? Is there a significant way to draw a view in a faster way?
What's my goal?
Say if I have different activities in an android app; the second time I visit an activity, I want it to "render" faster to optimize the performance and usability. Is there a way, like caching for example, or any other way? Or am I stuck with re-creating each activity from scratch from XML Layout or programmatically?
Thanks in advance for any thoughts..
the second time I visit an activity, I want it to "render" faster to optimize the performance and usability
Well, it will do that to an extent on its own, as your resources will already be loaded into the process.
You can also bring an existing instance of the activity to the foreground, creating a fresh one if there is no currently-running instance, via things like FLAG_ACTIVITY_REORDER_TO_FRONT. However, that's more of a way of controlling navigation, more so than specifically addressing performance.
You are also welcome to minimize your number of activities, going with more of a "fat activity" architecture, heavily leveraging fragments, where you can do a bit more caching of actual views.
If you have existing code that is exhibiting performance issues, use tools like Traceview to figure out where your time is being spent, rather than just guessing.