I want to call onNewIntent when the first intent on onCreate was finished and the browser was closed, but I don't know can I do this. I found in android developers and goggling but I don't understand.
Can someone show me an sample example? thanks
You can use,
Intent in=new Intent(yourcurrentactivity.this, secondactivity.class);
starActivity(in);
For open secondactivity class from yourcurrentactivity.
and also add activity tag on manifest file.
Related
I have a react native project. And there is a service running in the background.
When the app is not running, the service is still alive, and it may want to start the MainActivity in some time. I’m using the following code to start MainActivity(I tried noFlag/addFlag/setFlag):
Intent Intent = new Intent(context, MainActivity.class);
// intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
// intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(key, value);
context.startActivity(intent);
The AndroidManifest.xml is declared like:
<activity
android:name=".MainActivity"
android:launchMode="singleTask”>
</activity>
Each time the MainActivity will be created twice. In the first time we can get the extra value, but the second time it will be empty.
How can I make sure the MainActivity will only be created once?
Thanks.
Just found the problem. My method breakpoint on startActivity worked.
The third party sdk cannot find property receiver, so it send a startActivity call with intent flag FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK, which overrode my singleTask in AndroidManefest.xml.
As you most probably have known, the problem lies with you calling the startActivity twice. I think it would be lovely if you could show the code that calls the startActivity.
I have just now tested that as long as you have singleTask or singleTop as your launchmode, OnCreate wont be called twice. As you can read from here : https://developer.android.com/guide/components/activities/tasks-and-back-stack
the function that would be called is onNewintent and if the putExtra is empty, it indeed can create a NPE
I hope that helps you, Good luck
I'm trying to recreate() and activity on Android. I need additional data to be passed via an Intent to the recreated activity. How can this be done?
The following code does not work.
getIntent().putExtra("flag",true);
recreate();
You can call recreate() and save your date into SharedPreferences. In this way you are free to do many things and also the previous activity is completely destroyed before NewActivity begin. Take a look at this deep StackOverflow answer.
Why don't you restart activity via Intent :
Intent intent = getIntent();
intent.putExtra("your","params");
finish();
startActivity(intent);
I have an activity that takes an "intent" to the browser, I see the page on which connect and when I return to my work I press the button to go back to my activity. The problem is that it gets stuck in the browser. Is there any solution? Thank you very much for everything and sorry for my English.
here is my code
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(/*my url*/));
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.addFlags(Intent.FLAG_FROM_BACKGROUND);
startActivity(intent);
The Intent you used is just to open browser. If you want to handle the result then you need to consider implementing Custom WebView Activity. So that you can do what ever you like with the browser.
Ahhhh... My bad.!!!!.. I have checked my manifest file ..and I have put NoHistory=true on my parent actvity.
I got log cat message from startAnotherActivity() method
private void startAnotherActivity() {
Log.i(TAG, "Entered startAnotherActivity()");
Intent intent = new Intent();
intent.setAction(ANOTHER_ACTIVITY);
intent.addCategory("android.intent.category.DEFAULT");
startActivity(intent);
}
Another activity doesn't start, no other messages in log cat.
How can I resolve this issue?
UPDATE#1:
Sorry, I forgot to mention that AnotherActivity is an Activity in the other application, and therefore ANOTHER_ACTIVITY == 'some.other.app.domain.ANOTHER_ACTIVITY'
Shouldn't Dalvik complain if it cannot find specified activity?
One possible reason may be not declaring other activity in the manifest. You can do this like the following:
<activity android:name="your.package.your.activity">
</activity>
And then you can start the activity by doing the following:
Intent intent = new Intent(CurrentActivity.this, NewActivity.class);
startActivity(intent);
Hope this helps.
Since it's an activity in another application, you may need to set the component (fully qualified package name and fully qualified activity name).
See here: How to start activity in another application?
Or here:
Launch an application from another application on Android
Finally I found out my mistake.
In the project there are two similar messages in two activities, so I thought that runs one, but that was another.
Thank you for your assistance!
I'm new to android. Please tell me how to navigate to a new page in android.
Thanks in advance.
Edit:How to start a new activity from an existing activity
In android to navigate to another page means you have to start another activity. for starting a new activity use this
Intent intent = new Intent(currentActivity.this, nextActivity.class);
startActivity(intent);
You should mention the next activity in the AndroidManifest file.
To change your page (i think you're refering to "Activities" in android you need to issue a so called "intent").
You cann do that by:
startActivity(new Intent(nextactivity,NextActivity.class));
or
startActivityForResult(new Intent(nextactivity,NextActivity.class),1);
if you want the new Activity to return any result to the activity who started the new one.
But what i recommend is, that you read this documentation here:
http://developer.android.com/guide/topics/intents/intents-filters.html
and come back to this question if you have need additional assistance on concrete problems on that topics.
i hope that helps.