I've implemented a custom logo for my ActionBar for Android.
Here's the image.
The issue now that I'm facing is how do I allow myself to be able to click on that back arrow,and bring myself to the previous activity?A huge thank you :D!
Do the following two things in your code:
FIRST:
Go to the Activity's code in which you want to put the back arrow and write the following code after setContentView...
getActionBar().setDisplayHomeAsUpEnabled(true);
SECOND:
Go to AndroidManifest.xml file and under the activity tag of another activity(from which you want to move after clicking on back arrow) put the following code
<activity
android:name="---------------------"//No change here
android:label="--------------------"//No change here
android:parentActivityName="<YourPackageName>.PreviousActivityName >//**Put this code here**
Where PreviousActivity is the one to which you want to move after clicking the back arrow button.
FOR EXAMPLE:
Your code has 2 activities namely Act1 and Act2,and suppose you want to navigate from Act2 to Act1 by pressing the ActionBar back arrow button present in Act2...Here your parentActivity is Act1.
Put the following code in Act2.java:---
getActionBar().setDisplayHomeAsUpEnabled(true);
Now go to AndroidManifest.xml and put the following code under Act2 tag:
Let's say your package name is:com.example.stack
<activity
android:name="---------------------"//No change here
android:label="--------------------"//No change here
android:parentActivityName="com.example.stack.Act1 >//**Put this code here**
Here: http://developer.android.com/training/implementing-navigation/ancestral.html
you will find all answers for this question. If you don't understand something, feel free to ask ;)
Related
.When I click "back arrow"on the titlebar it has to move back from TeacherAdminPanel to StudentAdminPanel but it goes out of system, I have tried a lot but cannot solve this, as myself introduce as a beginner for android.Please help me!
<activity
android:name=".teacher_admin_panel"
android:label="TeacherAdminPanel"
android:parentActivityName=".Student_AdminPanel"/>
//This is the code for Androidmanifest.xml
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
//This is the code for backarrow in the TeacherAdminPanel
When you shift activity, do you finish the activity you are going from? If you finish the activity you remove it from the activity backstack, hence you have nothing to go back to, so the app will close.
https://developer.android.com/guide/components/activities/tasks-and-back-stack
i have to jump from activity A to fragment2 in activity B(in the activityB, i use the viewpager,which contains four fragment).what i want is when i use the upNavigation of the actionbar ,i just jump to the exact second fragment.
can anyone help me?(i have searched for some related questions ,but it seems they all navigate in/between the fragments,which is not my want.)
Use this , detect the onclick
ViewPager.setCurrentItem(pageNumber);
above line will navigate you to that page
From Android Jellybeans, all sub-activities of Settings activity are having this back button at top left corner which calls the Settings activity. It behaves more like a 'up' button for navigation purpose.
I have android code, and I want to disable this button for few sub-activities like display, sound etc. in my build.
Any suggestions, where do I have to modify to disable this?
I tried out removing
android:parentActivityName
tag from particular Activity in the Manifest file, but it didn't work.
Try this
getActionBar().setDisplayHomeAsUpEnabled(false);
My objective is to you use one menu for all activities. For that, I have a base activity which consists of 2 methods: onCreateOptionsMenu() and onOptionsItemSelected(). In onCreateOptionsMenu(), I am creating a menu using MenuInflater.
Further, I have 2 activities which extends the above BaseActivity so that same menu is shown for both the activities. My issue is that, when my first activity is launched, options menu is shown, I move to second activity from the first. In the second activity also, when I press the menu button, I am able to view the menu. After that, using Back key press, I come to first activity again, the menu is also shown up there, But when I move to the second activity thereafter, menu is not shown to me.
Can you please post code of your Base Activity's onOptionsItemSelected and onCreateOptionsMenu?
Anyway, with no code available. And not enough clarity, I assume that the following will work for you...
add #Override
public void onBackPressed() {
finish();
}
to your base activity
Minimum SDK version could be the cause. If you reduce it to 13-, you should probably see the menu show up again. Good article on this subject: POST
I have read into the finish(); commands and the FLAG_ACTIVITY_CLEAR_TOP commands and also checked out Common Ware's answer on killing app, but I am not sure how to put this into my app.
Basically, I have a user click a button that takes them to the camera. The user then snaps a photo and it brings them to a layout view. The user then clicks a button that takes them to one of 2 views, depending on a some conditions.
The user is then allowed to either retake a photo, or go to the main menu (depending). My problem is, if the user goes back to the main menu, and snaps another, then another, etc...the activities stack, so when I click the 'Main Menu' button the app goes back through eached stack activity until finally it goes back to the main menu. Is there a way to kill each activity with one of these lines, so even if a user retakes a photo, they will only need to go back once to get to the main menu?
Thanks!
I use the noHistory parameter in the manifest to accomplish this. Here is an example of a manifest entry for a Activity that should not be placed in the history stack:
<activity android:name=".MyActivity"
android:label="MyActivityTitle"
android:noHistory="true" />