目前正试图从主应用程序调用另一个应用程序,这里是简短的图表:
Integer[][] a = {{1, 5, 4}, {3, 7, 8}, {2, 9, 6}};
AtomicInteger i = new AtomicInteger();
Map<Integer, List<Integer>> sortedAndGrouped =
Arrays.stream(a)
.flatMap(l -> Arrays.stream(l))
.sorted()
.collect(Collectors.groupingBy(x -> i.getAndIncrement() / a.length));
System.out.println(Arrays.toString(
IntStream.range(0, a.length)
.mapToObj(r -> sortedAndGrouped.get(r))
.toArray()));
- &gt;将任务代码发送到应用B - &gt; App A
(做一些任务)
App B
- &gt; (将结果返回给App A) - &gt; App B
这里App A如何调用App B并发送任务代码:
App A
以下是App B上的清单:
private void attemptFacialRecognition(){
Intent intent = new Intent();
intent.setAction("com.yai.facerecognitionapp.FACIAL_RECOGNITION");
if(intent != null){
// We found the activity
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
// 0x10000000 = login
intent.putExtra(FLAG_ACVITY_TASK, FLAG_ACTIVITY_LOGIN);
LoginActivity.this.startActivityForResult(intent, FLAG_REQUEST_CODE);
}
}
此处App B将结果返回给App A:
<application
android:hardwareAccelerated="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="false"
android:theme="@style/AppTheme">
<activity android:name="com.yai.facerecognitionapp.FaceRecognitionAppActivity"
android:screenOrientation="portrait"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.yai.facerecognitionapp.FACIAL_RECOGNITION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
以下是App A从App B获取结果的方式:
private void resultActivity(boolean result){
Intent intent = new Intent();
intent.putExtra(FLAG_ACVITY_RESULT, result);
intent.putExtra(FLAG_ACVITY_TASK, TASK);
setResult(Activity.RESULT_OK, intent);
finish();
}
每次尝试获取@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == FLAG_REQUEST_CODE && resultCode == RESULT_OK && data != null){
Log.e("xxx", " " + requestCode + " " + resultCode);
Bundle bundle = data.getExtras();
if(bundle != null){
Boolean res = data.getBooleanExtra(FLAG_ACVITY_RESULT, false);
Log.e("XXX", res);
}
时,都会返回getStringExtra
。
这是日志猫:
Null Pointer Exception
我错过了什么?我无法弄清楚,很多人都是从SO中读到的,没有人不行。尝试过不同的方法,仍然坚持这个问题。
感谢。