I have two activities in my application.one of the activity started by service class ,so i have set the flag FLAG_ACTIVITY_NEW_TASK and start the activity.
in that activity i hide the status bar by using the following code .
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN)
The problem is some time the activity not hiding the statusbar.After doing several testing i found that the FLAG_ACTIVITY_NEW_TASK is creating problem.
how to solve this?
What if you do that directly in the XML:
<activity android:name=".ActivityName"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"/>
Related
I am opening an Activity when a button is pressed. However, if user presses this button twice fast enough my activity launches two times. To prevent that I added launchMode: singleTop in manifest and also added this flag to launching intent.
But still the behaviour is same. I am not looking to prevent double clicking by using handler threads or enabling disabling it. I wish to know why singleTop is not working in this case.
code in Manifest
<activity
android:name=".MyActivity"
android:screenOrientation="portrait"
android:theme="#style/MyTheme"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustResize" />
Intent
val intent = Intent(context, MyActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP
activity?.startActivityFromFragment(this, intent, REQUEST_CODE)
Update
Upon more investigation I found that startActivityForResult is not respecting the flag. startActivityFromFragment calls startActivityForResult
I wrote a sample which reproduces this here
You don't need to use signeTop. You can use any delay method on your button so that it won't get clicked immediately next time. If you are using rx android you can use below method. or you can create your own simple logic.
RxView.clicks(view).throttleFirst(500, TimeUnit.MILLISECONDS).subscribe(empty -> {
// action on click
});
I am facing an issue since upgrading Android Studio to 2.2... whenever I create a new activity in a project, the name of the project is getting displayed on the ActionBar of the new activity rather than the name of the new activity created. I have just learned intent and the transition from 1 activity to another is just fine but the action bar has the name of the project rather than the name of the current activity. What should i do?
Declare label in manifest:
<activity
android:name=".your_activity"
android:label="name_your_activity_label"/>
<activity
android:name=".your_activity"
android:label="name_your_activity_label" />
Example is just demonstration, edit in future. :P
I have a problem with an activity which is started with FLAG_ACTIVITY_REORDER_TO_FRONT is not recreated and present on the screen after FLAG_ACTIVITY_CLEAR_TASK.
So the step is:
Open app, enter Welcome Activity.
Finish Welcome activity and start activity A without specific intent flag.
Start activity B with FLAG_ACTIVITY_REORDER_TO_FRONT from activity A (new instance of B is created and now stack became A->B).
Start activity A from B with FLAG_ACTIVITY_REORDER_TO_FRONT (existing A instance brought to top of stack so stack became B->A).
And under some condition, I need to start over from the beginning (just like another normal app launch), so started Welcome activity using FLAG_ACTIVITY_CLEAR_TASK.
So the app will enter phase 2 again after phase 1, which is what I expected, but then, if I try to start activity B again with FLAG_ACTIVITY_REORDER_TO_FRONT from activity A, there is activity B's callback 'onNewIntent, onStart, onResume' in a row, but it doesn't present on the screen.
It looks like to me that there is still the previous instance of activity B somewhere but not showing to me.
I don't specify launch mode for either activity A or B.
I know that document says about FLAG_ACTIVITY_CLEAR_TASK that "This can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK.". And use them together does solve my problem, but then if I click home button to put app background and then launch again, it will become another app launch (enter phase 1) but not back to the previous top activity.
So my questions are:
When I use FLAG_ACTIVITY_CLEAR_TASK to start welcome activity, I don't see onDestroy of either activity A or B, is it by design?
If they are not destroyed, where do they stay and can I have a reference to them?
How can I make activity B presented on the screen after all of these steps?
Code for phase 5:
Intent i = new Intent(A.this, WelcomeActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
Thanks in advance.
AndroidManifest.xml
<activity
android:name=".activity.WelcomeActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.A_Activity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:theme="#style/BaiduMapTheme.MainMap"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".activity.B_Activity"
android:configChanges="locale|fontScale|keyboard|keyboardHidden|layoutDirection|mcc|mnc|navigation|orientation|screenLayout|screenSize|touchscreen|uiMode"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateVisible" />
OK, now I think I have those questions because of my incorrect using of the intent flags.
First of all, I should use FLAG_ACTIVITY_CLEAR_TASK and FLAG_ACTIVITY_NEW_TASK at the same time as the document says.
Then everything looks normal and as expected, except one that: if I put the app into background and then click the launch icon again, the WelcomeActivity will be created again.
Previously I thought my existing activity stack is cleared and a new WelcomeActivity is created, but it turns out the existing activity stack is still there, but an extra WelcomeActivity is created, so what I need to do is add some extra flag in WelcomeActivity to determine if it's created in this condition, if yes, then just call finish() in onCreate(), then I can back to the previous activity I was in before enter background.
I have an android application with several activities .Each and every activity has Application Icon in action bar which helps user to return back to main activity directly instead of pressing back button.My problem is that when I use the icon to start my home activity it does not uses the previous instance from the stack and start creating it again.
My Action bar app icon code is :
startActivity(new Intent(this, DashBoard.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
this above code starts Dashboard activity and calls its both onCreate() and onResume().But If I uses back button to return to this activity from any activity it just calls onResume().
Activity definition from manifest file:
<activity
android:name=".DashBoard"
android:configChanges="keyboardHidden"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
Why is this happening?Am I missing something to prevent it from not creating it again?Please help
Thanks
Use setFlags(), instead of addFlags(). You are on right track. Use the following code.
Intent intent = new Intent(this, DashBoard.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
Remove the FLAG_ACTIVITY_CLEAR_TOP.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Android Launch an application from another application
I am having a problem and it is the following one:
I have two applications, and I want to launch one of the activities from one app by the other one......I am gonna give an example:
first app package:
"es.wul4.android.app1"
second app package:
"es.wul4.android.app2"
What I want is to launch the activity whose class is called "Identificar" from the app1
This activity is NOT the main one. I tried by doind that:
Intent intent = getPackageManager().getLaunchIntentForPackage("es.wul4.app2.Identificar");
startActivity(intent);
But what i get doing that is nothing, it tells me that the app doesn´t exists.
If i try doing that:
getPackageManager().getLaunchIntentForPackage("es.wul4.app2");
startActivity(intent);
And it launch one activity, but the main one........
How can I launch this particular Activity inside the package "es.wul4.app2.Identificar"??
Thank u very much.
What you need to use are intent-filters. Assume the activity to be launched is in the package launch.me. Inside this applications manifest all the activities (main or otherwise) will be decalred by the <activity> tag.
Assuming the activity you want to launch is inside the class file Launchme. Then a portion of your manifest will be something like:
<activity android:name="launch.me.Launchme"
android:label="#string/app_name">
<intent-filter>
<action android:name="launch.me.action.LAUNCH_IT"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
Now in the activity from where you want to launch the above activity use:(Note: This activity can be in any package anywhere. You have to make sure that both, the calling and the called packages are available on the device)
Intent i=new Intent();
i.setAction("launch.me.action.LAUNCH_IT");
startActivityForResult(i,0);
You can use other methods for starting the intent other than startActivityForResult, thats upto you.
Did you add activity inside app1s manifest?:
<activity
android:label="#string/app_name"
android:name=".Identificar" >
</activity>
I think, since both activities are in the same package that you only have to do:
startActivity(new Intent(getApplicationContext(), Identificar.class));