2016-08-09 37 views

回答

0

要做到你想做的一種方法是使用廣播接收器,其中應用程序B通過一些信息(通過附加意向傳遞)接收特定的意圖。

應用A不能訪問的應用程序B.

共享偏好(或內部數據庫)例如(在應用程序B實現此):

public class MyReceiver extends BroadcastReceiver { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     Toast.makeText(context, "Intent Detected.", Toast.LENGTH_LONG).show(); 
     // Setup look and feel of App B 
    } 
} 

在應用B的MainActivity:

public onCreate(...) { 
    registerReceiver(new MyReceiver(), new IntentFilter("com.myapp.foo.CUSTOM_INTENT")); 
} 

在應用程序A(打電話給你在應用B廣播接收機):

public void broadcastIntent(View view) { 
    Intent intent = new Intent(); 
    intent.setAction("com.myapp.foo.CUSTOM_INTENT"); 
    sendBroadcast(intent); 
} 

希望這可以幫助你!

相關問題