I'm doing a tab activity composed with fragments. In one of my fragments I launch an activity from which I'd like to get back with the arrow on the upper left.
I've tried to declare my fragment as an activity and it works like that but I'm not sure of the viability of such a thing since Android still says " is not assignable to 'android.app.Activity'"
<activity android:name=".ParameterFragment"/>
<activity android:name=".parameters.ChangeMailActivity"
android:parentActivityName=".ParameterFragment">
<meta-data android:name="android.support.PARENT_ACTIVITY"
android:value=".ParameterFragment"/>
</activity>
Related
I don't want to move layout up in fragment.
I have attach activity screenshot.
AndroidManifest.xml
Add android:windowSoftInputMode="adjustPan" in your Manifest activity tag
<activity
android:name="ACTIVITY NAME"
android:exported="false"
android:windowSoftInputMode="adjustPan" />
Problem:
My Launching Activity creatively named LoadingActivity's onCreate method is called 2 times.
Manifest Content:
<manifest>
<application>
...
<activity
android:launchMode="singleTop"
android:name="com.awesome.app.activites.LoadingActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
</application>
</manifest>
First onCreate call is called with Bundle savedInstanceState which is null, shortly after which the onCreate method is called again, but this time with Bundle savedInstanceState which contains the following serialized content:
Bundle[{com.google.app_measurement.screen_service=Bundle[{referrer_name=LoadingActivity, id=1612091517631091562, name=null}], android:viewHierarchyState=Bundle[{android:views={16908290=android.view.AbsSavedState$1#a24446f, 2131296302=android.view.AbsSavedState$1#a24446f, 2131296313=android.view.AbsSavedState$1#a24446f, 2131296424=android.view.AbsSavedState$1#a24446f, 2131296445=android.widget.ProgressBar$SavedState#b25257c, 2131296581=android.view.AbsSavedState$1#a24446f, 2131296582=android.view.AbsSavedState$1#a24446f}}], androidx.lifecycle.BundlableSavedStateRegistry.key=Bundle[{}], android:lastAutofillId=1073741823, android:fragments=android.app.FragmentManagerState#a24ee05}]
Yes, this doesn't mean much, but it may be related to something at the bottom of the post.
Tried:
I have tried setting launchmode settings with android:launchMode="singleTop" for the LoadingActivty in my AndroidManifest.xml, but this does not help at all, it still runs the onCreate 2 times.
I have gone through my onCreate method, no where do I onCreate again or change ApplicationContext settings i.e. Orientation (physically or programmatically), etc.
Any idea why this happens and what I can do to resolve it.
For what it is worth, I have recently updated my deps and see this in my Manifest:
It compiles (change the package name for obv reasons) with the portrait launchmode, but I think this may have something to do with the double launch
I'm working on an app that, thought the method setHomeAsUpIndicator, replaces the title of the activity. So far everything makes sense because it can be understood by reading the documentation, but I can't figure out why, when I press the icon, a certain Activity is launched.
This specific part of the code looks like this:
private void myMethod() {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(
ContextCompat.getDrawable(this, R.drawable.someIcon)
);
actionBar.setHomeActionContentDescription(
getResources().getString(R.string.correspondingDescription)
);
actionBar.setDisplayShowTitleEnabled(false);
}
When someIcon is pressed, another Activity is launched, but I don't know where is that indicated.
Thanks for the help!
It moves to previous activity because there is a parent activity set in a AndroidManifest.xml file, like this :
<activity
android:name=".ExampleActivity"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
</activity>
I am trying to start a new activity when an Android device is rotated, but I don;t even seem to be detecting the rotation in the emulator.
I've read the thread at Android: listen for Orientation change? and that all seems to amke sense, but its just not working.
In my manifest I have:
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and in my mainActivity.java I have:
#Override
public void onConfigurationChanged (Configuration newConfig) {
super.onConfigurationChanged(newConfig);
int orientation=newConfig.orientation;
switch(orientation) {
case Configuration.ORIENTATION_LANDSCAPE:
showMessage("landscape");
break;
case Configuration.ORIENTATION_PORTRAIT:
showMessage("portrait");
break;
}
}
This obviously won't start the new Activity, but I am trying to get the orientation detection working first (showMessage just calls a Toast and is working elsewhere in my code, so that's not why I am not seeing anything).
When I run this in the emulator and use the rotate buttons, the emulator rotates as expected but I never see the Toast...
Where am I going wrong? (I am importing android.content.res.Configuration as required for the Configuration constants).
onConfigurationChanged method will not be invoked when you rotate your device, actually, nothing will be invoked because of this line:
android:screenOrientation="portrait"
device is just locked in a portrait mode, remove this line, and onConfigurationChanged method should be invoked.
If you want to detect that device is rotated and keep android:screenOrientation="portrait" line you can use accelerometer sensor.
Try after removing this lines
android:configChanges="orientation|screenSize"
android:screenOrientation="portrait"
because you are locking screen orientation in manifest and you are
also overriding on config change in activity.
I use Android Studio 1.5 to create an Android application.
I added a blank activity using context menu but I forgot to define a hierarchical parent for that activity.
So I changed in AndroidManifest.xml this
<activity
android:name=".CategoriesActivity"
android:label="#string/title_activity_categories"
android:theme="#style/AppTheme.NoActionBar">
</activity>
to this
<activity
android:name=".CategoriesActivity"
android:label="#string/title_activity_categories"
android:parentActivityName=".CitiesActivity"
android:theme="#style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="info.emitikon.mycity.CitiesActivity" />
</activity>
Anyway I cannot see the BACK arrow button at the top menu.
What do I am missing here?
Add these lines in the onCreate method of your Activity:
ActionBar = getActionBar(); // or getSupportActionBar() if you are using the suport library
actionBar.setHomeAsUpIndicator(R.drawable.ic_launcher); // your custom icon
actionBar.setDisplayShowHomeAsUpEnabled(true);