Sending Intent inside of another Intent

狂风中的少年 提交于 2019-12-05 13:08:36
Tom

I actually figured it out, the solution was quite simple. mLaunchIntent should not be cast to Parcelable or the data gets lost.

mSendingIntent.putExtra(Intent.EXTRA_INTENT, mLaunchIntent);

That was all that I needed to send an Intent through another Intent.

You can put an Intent to an Intent with:

Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_INTENT, new Intent());

To retrieve the Intent (from within an Activity) from the intent you can do the following:

Intent intent = getIntent().getParcelableExtra(Intent.EXTRA_INTENT);

Can't you use a service to parse the Intent?

There are different ways you can pass intents / objects from source to destination and vice versa. One way of doing it without using bundles or extras would be resorting to the usual class methods with variables (getters and setters). Pass the objects using methods. Another way of doing it would be the use of class variables. Ex:

public class ClassB  extends Activity{
    public static Object myObject;
    ...
}

public class ClassA extends Activity{
    ...
    @override
    protected void onCreate(Bundle savedInstanceState){
        Object myObject = ClassB.myObject;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!