[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: AndroLua how to call android.intent_for_result()
- From: steve donovan <steve.j.donovan@...>
- Date: Tue, 24 May 2022 16:40:44 +0200
Hi Fero,
Well you are probably more of an expert on AndroLua (and Android) as I
am, since it is years since I did any Android development!
So I wish you good luck - and if you get somewhere, maybe you would
like to take this one over?
regards,
Steve D
On Tue, May 24, 2022 at 12:04 PM Fero Dali <ferodali@riseup.net> wrote:
>
> I have made some progress and two files run almost as intented.
> They run if I use
> me:luaActivity('second')
> instead of
> me:intent_for_result(myIntent, callback)
> but of course now my app.lua does not receive result from second.lua
>
> How do I create myIntent? I tried with
> myIntent = Content.Intent(me.a, SecondActivity.class)
> but it does not work because SecondActivity.class is null.
>
> Thanks
> Fero Dali
>
>
> File app.lua
> local android = require 'android'
> local SecondActivity = require'second'
> local LPK = luajava.package
> local Content = LPK 'android.content'
>
> local RESULT_OK = -1
>
> local MAIN = android.new()
> function MAIN.create(me)
> local btn, txt
> local myIntent
> --- WHAT TO DO HERE?
> -- from java code
> -- Intent myIntent=new Intent(MainActivity.this,SecondActivity.class);
> -- myIntent = Content.Intent(me.a, SecondActivity.class)
>
> local callback
> callback = function(request, result, intent)
> print(string.format('Callback request: %d, result: %d', request, result))
> if result == RESULT_OK then
> local text = intent:getStringExtra('MESSAGE')
> txt:setText(text)
> end
> end
>
> btn = me:button('Start new Activity for result', function()
> -- me:intent_for_result(myIntent, callback)
> me:luaActivity('second')
> end)
> txt = me:textView('Type some text in another activity')
>
> return me:vbox{
> btn,
> txt,
> }
> end
> return MAIN
>
>
> File second.lua
> local android = require 'android'
> local LPK = luajava.package
> local Content = LPK 'android.content'
>
> local RESULT_OK = -1
>
> 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()
> local myIntent = Content.Intent()
> myIntent:putExtra('MESSAGE', message)
> me.a:setResult(RESULT_OK, myIntent)
> me.a:finish() -- finish activity
> end)
> return me:vbox{
> edit,
> btn,
> }
> end
> return MAIN