In Splashscreen Activity inside I implemented the

2020-04-14 07:55发布

问题:

Interface class:

interface MyCustomInterface {
     fun get_msg( str: String)

}

SplashScreen Activity:

class SplashActivity : AppCompatActivity(),MyCustomInterface {
    override fun get_msg(str: String) {

    }

val socket=MysocketIO(this)
    }

MySocketIO class where I added the data to interface from server:

class MysocketIO(var mainActivity: SplashActivity) : Thread() {
    fun enable_data_event():Boolean {
        try {
            data_event_registered.set(true)
            socket!!.on(this.data_event_id, object : Emitter.Listener {
                override fun call(vararg args: Any) {
                    receive_data_queue.add(args[0] as String)
                    data_recieved.set(true)
                    mainActivity.get_msg(receive_data_queue.peek())
                }
            })
            return true
        }
        catch (ex : java.lang.Exception){
            ex.printStackTrace()
        }
    }
}

How to get data from SplashScreen to another activity?

回答1:

Try to create one global veriable to store interface data after then pass intent to activity.. like ..

class SplashActivity : AppCompatActivity(),MyCustomInterface{
var data=""
override fun get_msg(str: String) {
    data=str
}

after when to start any activity to pass data into intent like..

intent.putString(key,data)