Alessio Trecani
Alessio Trecani

Reputation: 733

Retrieve information from a function used in another application Android

I have an application that have a timer that every x seconds change the textview text with a random number.

  @Override                    
public void run() {   
        TextView t = (TextView) findViewById(R.id.tv);
        while(true){
           Random r = new Random();
           int i1 = (r.nextInt(805) + 650);  
           t.setText(i1.toString());                                                            
           try {
               Thread.sleep(i1);
           }catch (Exception e) {
               tv1.setText(e.toString());
           }           
        } 
}    

I need to create a second application that retrieve the random number "i1" everytime that this number is generated (or everytime that the textview changed text).

Is possible to do so in some way?

Upvotes: 1

Views: 36

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007228

I need to create a second application that retrieve the random number "i1" everytime that this number is generated (or everytime that the textview changed text).

This implies two things:

  1. The user is not involved in requesting that the data be shared (e.g., there is no button or action bar item or anything)

  2. The first application should push the data to the second application (versus the second application pulling the data, as it will not know when the data changed)

The simplest solution would be for the first application to send a broadcast via sendBroadcast() that is picked up by the second application using a BroadcastReceiver. The first application would send the broadcast "everytime that this number is generated (or everytime that the textview changed text)", so the second application has the latest value.

Upvotes: 2

Related Questions