how to make professional back button in action bar - java

I made back button by using activity parent and getactionsupport just like this:
<activity
android:name=".News_details"
android:parentActivityName=".Main2Activity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.package.Main2Activity" />
</activity>
I also add this to my activity in the manifest.
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
so what the result that I get ?
The blue arrow displays properly when I run my app in android version 4.+. When I use android version 5.+ the blue arrow reveres direction.

Related

Shows only black screen when moving to another activity

I don't know what I've done, but after I restart the Android Studio and when i run the app, it just shows only black screen when I'm calling new activity from previous activity.
The app is running good before I restarted the Android Studio.
I don't find where the wrong code is. There is no error based on the IDE.
I have this in onCreate
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
I have launched the activity by this code:
context.startActivity(new Intent(context, homeActivity.class));
in the previous class
I've seen many answers here, but do not solved my problem.
EDIT
Screenshot after calling the homeActivity
Follow CamelCase for naming conventions for Java classes check homeActivity.class --> HomeActivity.class
Ensure you define homeActivity.class in your manifest.xml
<application
android:allowBackup="true"
android:supportsRtl="true"
android:installLocation="auto"
tools:replace="android:supportsRtl"
android:icon="#mipmap/app_icon"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/AppTheme" >
// ... Other activity
<activity
android:name=".HomeActivity"
android:screenOrientation="portrait">
// ... Other meta-data & services.
</application>
Try create another activity with the same layout and class, but name it by the big letter.

Android dialog theme makes setContentView crash the application

I'm applying this theme from manifest :
<activity
android:name=".ui.rate.MyActivity"
android:theme="#android:style/Theme.Dialog">
</activity>
With this the application crash on setContentView() of MyActivity. If I remove it there is no crash but I need this theme
In the activity onCreate() i'm doing this :
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_rate);
getWindow().setBackgroundDrawableResource(android.R.color.transparent);
Even if I remove the first and third lines the applicatio ncrash the same way. It's really the dialog theme that's causing the crash
How can I set it so that Android accept it ?
You can use Theme.AppCompat.Dialog as the theme of your activity to avoid
compatibility problem.
The activity will be presented as a dialog.
<activity
android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.Dialog">
</activity>
As for the title, you can use setTitle("Hola!"); to change it.
If you wanna remove the title, just call:
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
for android:theme="#style/Theme.AppCompat.Dialog",
and:
requestWindowFeature(Window.FEATURE_NO_TITLE);
for android:theme="#android:style/Theme.Dialog".

I can not hide Title bar

I use this code in manifest for hide title bar, but i cant run my application:
<activity
android:name="com.example.MainActivity"
android:theme="#android:style/Theme.NoTitleBar"
android:screenOrientation="portrait"
android:label="#string/app_name" >
Try using a physical device to test your app... Well I tried to hide the NoTitleBar but it became invisible instead!!
http://developer.android.com/tools/device.html

Android notification bar persists on the all Application screen(never goes)

I have a screen in my app with a button to set date/time in the OS. I use startActivity(new Intent(android.provider.Settings.ACTION_DATE_SETTINGS)) to open the android's date/time screen .
After setting the date/time , i return to my app screen using the back button in the android's status(notification) bar. After this, the notification bar never dissappears from my app screens. Its persistent until i restart my application. Is there a way to remove the notification bar?
I have added the line "android:theme="#android:style/Theme.NoTitleBar.Fullscreen" to all my activities and even at at the application level(just inside )
But still it never goes
Here is a part of my manifest
<activity
android:name="com.cyberonics.progsoundapp.ui.AlarmSettingScreen"
android:configChanges="keyboardHidden|orientation"
android:label="#string/title_activity_alarm_setting_screen"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
</activity>
I also have the following code in my activity class
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN) before SetContentView()
Is there anything else i am missing?
Request your guidance on this
Thank you

How can I show a specific activity when application enters foreground from background?

I have an application with several activities.One of them is Login activity and this activity defined as MAIN in my app in manifest:
<activity
android:name="com.company.myapp.AuthorizationMainActivity"
android:label="#string/app_name"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The problem when my app enters background (e.g. I press home button) and then I open the app again - the Login page is showed to me. How can I show activity which was active for user at the moment application enter background?
If you don't explicitly want to use it for a special requirement, remove "android:launchMode="singleTask".
A "singleTask" activity allows other activities to be part of its task. It's always at the root of its task, but other activities (necessarily "standard" and "singleTop" activities) can be launched into that task. (found here at Android Developes)
Use a dummy activity as your base activity that launches and in that activity check to see if you need to display the login activity or another one. Then start that specific activity you want to go to from the dummy activity.
make sure you set the dummy activity to noHistory in the manifest so the user cannot navigate back to it
if(needsLogIn){
Intent i = new Intent(this,LoginActivity.class);
startActivity(i);
}else{
Intent i = new Intent(this,OtherActivity.class);
startActivity(i);
}
Remove android:launchMode="singleTask" > singletask activity will be the root and when you press home button all the activities above it will be removed. when you remove android:launchMode="singleTask" then the default behaviour will take place ie when you press home button and then launch again it will open the activity from where you left. have a look at the link http://developer.android.com/guide/components/tasks-and-back-stack.html

Categories