lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Finaly I got this exaple working!
Basicaly I am using power of Lua instead of Java.
I guess I would be need to be careful what variable
I use for returning result.

This works on my android emulator, I hope it should work OK.

Thank you very much for all replies
Fero Dali

PS: and you can check where I used this at https://github.com/ferodali/game_15

File app.lua
local android = require 'android'
local SecondActivity = require'second'
local txt
local MAIN = android.new()
function MAIN.create(me)
  local btn
  btn = me:button('Start new Activity for result', function()
                    me:luaActivity('second')
  end)
  txt = me:textView('Type some text in another activity')

  return me:vbox{
    btn,
    txt,
  }
end
function MAIN.onResume()
  if SecondActivity.result then
    txt:setText(SecondActivity.result)
    SecondActivity.result = nil
  end
end
return MAIN


File second.lua
local android = require 'android'
local MAIN = android.new()
function MAIN.create(me)
  local edit, btn
  edit = me:editText()
  btn = me:button('Return from new Activity',
                  function()
                    local message = edit:getText():toString()
                    MAIN.result = message
                    me.a:finish() -- finish activity
  end)
  return me:vbox{
    edit,
    btn,
  }
end
return MAIN