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.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am creating a simple graphics application, where the user can draw several shapes, change the shape color-size, zoom, rotate the device etc. After researching, I found out that there are many options on how this can be achieved and I find it hard to choose which approach would benefit me more. One approach that I have started testing is to create a custom view and to draw on Canvas.
Is this option valuable in order to proceed without having the futuristic fear of low performance resulting to switch over something else (e.g. something like OpenGL)?
Or better, given the brief description above, what would you recommend as the best option?
As this is an opinion based type of question, I think this one might get closed, so I'll type fast: I think to get your app up and running fast, Canvas is your best approach (lots of easy docs and examples out there), unless you're already an export in OpenGL, to which there is quite a steep learning curve. It doesn't sound like, from your app requirements, you would hit upon any serious performance issues, and, as I say, you can get thing running quickly. If performance is not adequate, you can latter switch to pure OpenGL or use a framework for it like libGDX, Rajawali, AndEngine, etc.
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 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.
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 am trying to develop an app similar to paint app.
I want allow user to perform redo or undo operations over canvas.
I searched a lot, but dint find any example that explains about redo
and undo operations for Circle, Rectangle etc.
most of the tutorials explain redo and undo for Line.
Any help will be appreciated.
Store every operation in a list, then if you want to undo something just remove the last thing you put into the list. A linkedlist or a stack would work.
Pseudocode
Stack<Action> operations=new Stack<Action>();
Stack<Action> redos=new Stack<Action>();
Every time user have done something do
operations.push(new Action(actiontype,ccoordinates));
for undo
redoes.push(operations.pop());
to redo
operations.push(redos.pop());
and in your onDraw() method you draw everything thath is in operations...
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 am planning to make racing game in android.I have created many applications in different mobile technology. but i am pretty much beginner for game application. So my question is how can i make race track in android? How should i show that car is moving on that race track.
I have the images of cars and race track. But i have no idea how should i show the part of race track and how should show that car is moving on that track??
I suggest you download AndEngine ( an open source 2d android game develoopmnent framework ). In the examples there is a (very simple) race track demo with a movable car + controls + obstacles. If you have troubles you can always get support from the forums
AndEngine has a very easy learning curve :-)
Have fun creating your racing game!!
Here are 2 good tutorials on starting with 2d:
- Canvas tutorial
- OpenGL tutorial
The last part, about showing only a part of the map, can be achieved by using a BoundCamera in AndEngine.
You should start with studying the 2D graphics capabilities of the Android library. Here's another good reference article. It lists some drawing options including drawing to the Canvas object which is probably the right choice for the kind of game you're describing.
Here's a full but simple example of handling the onDraw event for a canvas and performing custom drawing. Here's a small bit of the code:
paint.setColor(Color.BLUE);
canvas.drawCircle(20, 20, 15, paint);
The above is a simple example that draws a circle with a particular size to a particular location on the canvas. It's a good place to start. To finish your game you'll be drawing bitmaps which is a more complex process but conceptually similar.