3

我在后台线程中对数据进行了一些操作,并且在我想要求用户选择相应的活动来处理结果之后:

Intent chooserIntent = Intent.createChooser( intent, getString( R.string.select_application_for, intent.getData() ) );
chooserIntent.putExtra( Intent.EXTRA_INITIAL_INTENTS, intents.toArray( new Parcelable[ intents.size() ] ) );
startActivity( chooserIntent );

但是我总是在下一个 StackTrace 崩溃:

android.app.SuperNotCalledException: Activity {android/com.android.internal.app.ChooserActivity} did not call through to super.onCreate()
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2025)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

如果我评论行:

chooserIntent.putExtra( Intent.EXTRA_INITIAL_INTENTS, intents.toArray( new Parcelable[ intents.size() ] ) );

崩溃消失了,但这不是我想要做的。

我想知道是否有人已经解决了这个难题。

4

1 回答 1

2

问题已在以下评论中解决:

从源头上看,看起来 !(pa[i] instanceof Intent) 正在为您的一个或多个意图评估为 true,pa 是 intents.toArray(new Parcelable[intents.size()])。你可以使用 Log 语句来确认意图中的项目确实通过了 intents.get(i) instanceof Intent 吗?

资源:

public class  [More ...] ChooserActivity extends ResolverActivity {
    @Override
    protected void  [More ...] onCreate(Bundle savedInstanceState) {

    ....
    ....

    Parcelable[] pa = intent.getParcelableArrayExtra(Intent.EXTRA_INITIAL_INTENTS);
        Intent[] initialIntents = null;
        if (pa != null) {
            initialIntents = new Intent[pa.length];
            for (int i=0; i<pa.length; i++) {

                // The check for if-statement is evaluating to `true`
                if (!(pa[i] instanceof Intent)) {
                    Log.w("ChooseActivity", "Initial intent #" + i
                        + " not an Intent: " + pa[i]);
                    finish();
                    return;
                }
                initialIntents[i] = (Intent)pa[i];
            }
        }
        super.onCreate(savedInstanceState, target, title, initialIntents, false);
    }
于 2013-09-01T20:22:22.260 回答