兩個獨立 Android 項目(so、TestRotateAnim)合併為一個 APK,在 so 中點擊按鈕跳轉到 TestRotateAnim 功能頁。
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="com.example.ACTION_START_ROTATE"/>
</intent-filter>
</receiver>
Intent intent = new Intent("com.example.ACTION_START_ROTATE");
sendBroadcast(intent);
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, TargetActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
模塊解耦,無需直接依賴對方類,支持動態擴展。