In my android app, if I have an activity called Home.java, how could I get the string "Home" on the oncreate event of that activity?
Thanks.
this.getClass().getSimpleName()
Related
I created an android app and i want to start my app at the MainActivity every time my app is launched? That is if my app is at activity B and the user press the home key, then when the app is launched again, it starts at MainActivity instead of activity B? how i can do that ?
There is a flag for exactly this purpose. In the <activity> declaration for your MainActivity add:
android:clearTaskOnLaunch="true"
This will cause the app to start at MainActivity whenever it is relaunched.
There are few ways to do this -
In your activity B override the 'onPause' method and add 'finish()'
In your manifest file where you have added <activity> tag for your activity B, you can add 'android:noHistory=true'. Check this link to understand more - https://developer.android.com/guide/topics/manifest/activity-element
I hope this will solve your issue.
I'm trying to update the subtitle of my toolbar from an adapter class. I've tried the accepted answer from here.
((OrderActivity) context.getSupportActionBar().setSubtitle("Bla Bla"));
Order Activity is the calling activity and this line of code is in the adapter. The context being used here is passed from the calling/parent activity.
I'm getting a 'cannot resolve method getSupportActionBar()'.
try ((OrderActivity) context).getSupportActionBar().setSubtitle("Bla Bla");
I have 2 Activities, say activity A and activity B. I have to call activity B from the activity A. Now that is done by using Intent. There is some code in the activity A that must be executed after activity B ends. How can that be done?
I use the following code :
Intent intent = new Intent(A.this, B.class);
startActivity(intent);
finish();
How can i accomplish that?
According to Android Docs: "Starting another activity doesn't have to be one-way. You can also start another activity and receive a result back. To receive a result, call startActivityForResult() (instead of startActivity())."
Activity For Result Doc
And here you have a question about Activity For Result where you will find an example.
I am beginner in android studio and When i click on button to transfer my activity from one to another then i am getting error:App is not responding? What's wrong with my code?
Here is first activity which is initial destination
Here is my Second Activity which is final destination
Your button b variable it is bad instantiated, you should declared as follows:
b = (Button) findViewById(R.id.simpleProgramDisplayDate);
I am developing android Application having number of activities. The requirement of the application is When i "FORCESTOP" the application manually(Settings->Applications->ManageApplication->APP_NAME->FORCESTOP), the last focused activity(UI Page) to be displayed. Can i get the Last focused Activity after *FORCESTOP*ing the Application? Please help me with the sample code.
You should keep track of each activity change and save it to file (e.g. in your sharedpreferences) immediately when the change happens. Something like this
protected void onResume() {
SharedPreferences.Editor edit = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()).edit();
edit.putString("LastActiveActivity", this.getClass().getName());
edit.commit();
super.onResume();
}
Make sure you save the current activity in the onResume() method of all your activities.
When you restart you can read the last activity back from your preferences. This should be done in the onCreate() method of your main activity (the one that is specified as "LAUNCHER" in your manifest). Then start the activity with the name you've read back.