java - How should I receive text input when using surface view for an Android game -


i've created android game based on this tutorial. have lot of development experience, these first steps java , mobile platform.

the game created single activity drawn on surfaceview , 'screens' specified break up. have no xml layout. oncreate main class best place see how it's set up. androidfastrenderview extends surfaceview.

    public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      requestwindowfeature(window.feature_no_title);     getwindow().setflags(             windowmanager.layoutparams.flag_fullscreen                     | windowmanager.layoutparams.flag_keep_screen_on,             windowmanager.layoutparams.flag_fullscreen                     | windowmanager.layoutparams.flag_keep_screen_on);      boolean isportrait = getresources().getconfiguration().orientation == configuration.orientation_portrait;     int framebufferwidth = isportrait ? 480 : 800;     int framebufferheight = isportrait ? 800 : 480;     bitmap framebuffer = bitmap.createbitmap(framebufferwidth,             framebufferheight, config.rgb_565);      float scalex = (float) framebufferwidth             / getwindowmanager().getdefaultdisplay().getwidth();     float scaley = (float) framebufferheight             / getwindowmanager().getdefaultdisplay().getheight();      renderview = new androidfastrenderview(this, framebuffer);     graphics = new androidgraphics(getassets(), framebuffer);     fileio = new androidfileio(this);     audio = new androidaudio(this);     input = new androidinput(this, renderview, scalex, scaley);     screen = getinitscreen();     setcontentview(renderview); } 

i'm looking way enable user enter name high scores table - thought simple. i'm struggling best way receive keyboard input. what's best option here? i'm assuming there's way can create custom edit can draw on surface view myself , receive keyboard input way. however, i'm guessing displaying edittext on top of surface view easier - can't life of me work out how it. i've tried numerous methods i've found through google , can't seem of them work.

advice , sample code appreciated.

many thanks

the best way using internal storage. can save files directly on device's internal storage. default, files saved internal storage private application , other applications cannot access them (nor can user). when user uninstalls application, these files removed.

to create , write private file internal storage:

call openfileoutput() name of file , operating mode. returns fileoutputstream. write file write(). close stream close().

`string filename = "hello_file"; string string = "hello world!"; fileoutputstream fos = openfileoutput(filename, context.mode_private); fos.write(string.getbytes()); fos.close(); 

mode_private create file (or replace file of same name) , make private application. other modes available are: mode_append, mode_world_readable, , mode_world_writeable.

to read file internal storage:

call openfileinput() , pass name of file read. returns fileinputstream. read bytes file read(). close stream close().

saving cache files

if you'd cache data, rather store persistently, should use getcachedir() open file represents internal directory application should save temporary cache files.

when device low on internal storage space, android may delete these cache files recover space. however, should not rely on system clean these files you. should maintain cache files , stay within reasonable limit of space consumed, such 1mb. when user uninstalls application, these files removed.

or use sqlite databases more detail here


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -