Perhaps I am going about this the wrong way, but I want to respond to my Android AppWidget's click event within my own app AND launch an Activity. At the time I set the PendingIntent
I have another Intent
which I want to launch when clicked. My onStartCommand
uses this line:
final Intent mLaunchIntent = (Intent) intent.getParcelableExtra(Widget.EXTRA_INTENT);
When I call setOnClickPendingIntent
I have this line prior:
mSendingIntent.putExtra(Widget.EXTRA_INTENT, (Parcelable) mLaunchIntent);
So even though mLaunchIntent
is a valid Intent
in both lines, the first line is missing a great deal of data. Calling startActivity
then fails because the Intent
is not valid.
I am wondering if it is possible, and how, to send an Intent
inside of another Intent
without strictly calling putExtras
because that method simple adds the extras from one Intent
to the next. I'd like to keep these two separate and easily accessible.
The following code demonstrates how you can start another activity via an intent. # Start the activity connect to the # specified class Intent i = new Intent(this, ActivityTwo. class); startActivity(i); Activities which are started by other Android activities are called sub-activities.
We can send the data using the putExtra() method from one activity and get the data from the second activity using the getStringExtra() method.
Most commonly, ACTION_SEND action sends URL of build-in Browser app. While sharing the data, Intent call createChooser() method which takes Intent object and specify the title of the chooser dialog. Intent. createChooser() method allows to display the chooser.
The flags you can use to modify the default behavior are: FLAG_ACTIVITY_NEW_TASK. Start the activity in a new task. If a task is already running for the activity you are now starting, that task is brought to the foreground with its last state restored and the activity receives the new intent in onNewIntent() .
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With