Cdacians

Cdacians
Cdacians

Tuesday, 7 August 2012

Start a specified app with data passed


Start a specified app with data passed

In the post Start a specified app, the slave app is satrted without any data passed. Data can be passed from master app to slave app in bundle.

Start a specified app with data passed

Master App:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.test.AndroidMaster;
 
 
 
import android.app.Activity;
 
import android.content.Intent;
 
import android.os.Bundle;
 
import android.view.View;
 
import android.widget.Button;
 
import android.widget.EditText;
 
 
 
public class AndroidMasterActivity extends Activity {
 
     
 
    final static String PACKAGE_NAME = "com.test.AndroidSlave";
 
    final static String CLASS_NAME = "com.test.AndroidSlave.AndroidSlaveActivity";
 
     
 
    EditText textIn;
 
    Button btnStartSlave;
 
     
 
    /** Called when the activity is first created. */
 
    @Override
 
    public void onCreate(Bundle savedInstanceState) {
 
        super.onCreate(savedInstanceState);
 
        setContentView(R.layout.main);
 
        textIn = (EditText)findViewById(R.id.input);
 
        btnStartSlave = (Button)findViewById(R.id.startalave);
 
        btnStartSlave.setOnClickListener(new Button.OnClickListener(){
 
 
 
            @Override
 
            public void onClick(View arg0) {
 
                // TODO Auto-generated method stub
 
                String textToBePassed = textIn.getText().toString();
 
                startSlave(textToBePassed);
 
            }});
 
    }
 
     
 
    private void startSlave(String passingText){
 
        Intent intent = new Intent();
 
        intent.setClassName(PACKAGE_NAME, CLASS_NAME);
 
         
 
        Bundle bundle = new Bundle();
 
        bundle.putString("key", passingText);
 
        intent.putExtras(bundle);
 
         
 
        startActivity(intent);
 
    }
 
}


akm
www.cdacians.com

No comments:

Post a Comment