を作成することによって、別のクラスのメソッド。
まずあなたがUSBCommunicationManager
オーバーライドonNewIntent
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
String action = intent.getAction()
//now you can check this action and use desired method
}
では、いくつかのカスタムアクション
public static final String SOME_ACTION1 = "some_action1"
public static final String SOME_ACTION2 = "some_action2"
private void someAction(){
Intent intent = new Intent(a, USBCommunicationManager.class);
intent.setAction(SOME_ACTION1)
a.startActivity(intent);//this calls onNewIntent method in launched activity
}
を初期化Helper.class
内
<activity ..
android:launchMode= "singleInstance" />
次に、あなたの活動にmanifest
に追加する必要がある。しかし、私はにお奨め読む約BroadcastReceiver
です。このソリューションを使用すると、誤ってアクティビティを起動する可能性があります。しかし、ブロードキャストを使用すると、アクティビティを破棄し、アクティビティの再起動について心配する必要はありません。
簡単に言えば、activity + interfaceまたはactivity + broadcastReceiverを使用して、アクティビティ内のメソッドを呼び出す必要があります。 –
答えに感謝します。私はアンドロイドの初心者であり、悲しいことにそれが何を意味するのか分からない。 – murkr