I've implemented inside my app the Up Navigation button in this way, inside my AndroidManifest.xml I wrote this:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".EventDetails"
android:label="#string/category_events"
android:parentActivityName=".MainActivity"
android:screenOrientation="portrait"/>
</application>
I didn't do anything else and everything works very good.
I read the official documentation and about the
android:parentActivityName=".MainActivity"
they say:
With the parent activity declared this way, you can navigate Up to the appropriate parent using the NavUtils APIs, as shown in the following sections.
This is my child activity code:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class EventDetails extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set the content of the activity
setContentView(R.layout.event_details);
}
}
So you can see that I don't implement NavUtils APIs, etc...
Now my question is this, why everything works?
NavUtils are a set of convenience methods for doing certain tasks, like launching your parent as a new task. They are not required for any android app, and there is basic functionality like back stack navigation present without any need to use them.
Also, I see you tagged this fragments- it has nothing to do with fragments. NavUtils is about navigating between Activities, not Fragments of a single Activity.
Related
So I have an app. It has 3 activities at the moment... I am using intents to launch the activities from one and another
MainActivity > ChallongeLogin > ChallongeEvents
In my MainActivity and my ChallongeLogin, there is a large bar at the top of the app that lists the name of my app. However, when I eventually read the ChallongeEvents, this bar disappears... I don't remember doing anything special to make this bar disappear. Why did it go away?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.testing.testingapp">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:screenOrientation="portrait"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:screenOrientation="portrait"
android:name=".ChallongeLogin" />
<activity
android:screenOrientation="portrait"
android:name=".ChallongeEvents" />
</application>
</manifest>
According to your requirement you must extends AppCompatActivity instead of Activity .
public class ActivityName extends AppCompatActivity {
// ...
}
AppCompatActivity is from the appcompat-v7 library. Principally, this
offers a backport of the action bar. Since the native action bar was
added in API Level 11, you do not need AppCompatActivity for that.
However, current versions of appcompat-v7 also add a limited backport
of the Material Design aesthetic, in terms of the action bar and
various widgets. There are pros and cons of using appcompat-v7, well
beyond the scope of this specific Stack Overflow answer.
Reference
Activity, AppCompatActivity, FragmentActivity, and ActionBarActivity: When to Use Which?
It is called ActionBar/ToolBar.
Extend the AppCompatActivity class instead of plain Activity class in that activity's java class.
I have an activity as a child within a navigation drawer parent activity, any time the orientation of the pages changes the page has to be reloaded again.
public class ApplicationsClass extends NavigationDrawer implements LoaderCallbacks<Cursor> {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getLayoutInflater().inflate(R.layout.main_list_activity, frameLayout);
if (savedInstanceState == null) {
//I do my stuffs here
}
}
...
}
In my AndroidManifest.xml
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="22" />
<!-- Main activity. -->
<application
android:largeHeap="true"
android:allowBackup="true"
android:theme="#style/AppTheme"
android:configChanges="orientation|keyboard|keyboardHidden|screenSize|screenLayout|uiMode">
<!-- Register Activity -->
<activity
android:name=".ApplicationsClass">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
</application>
I have tried adding android:configChanges="orientation|keyboard|keyboardHidden|screenSize|screenLayout|uiMode" to my application tag in the androidmanifest as some articles suggested but to no avail. Please is there a way to stop reloading the page upon orientation changes in android. I would be grateful if someone could help. Thanks in advance.
UPDATE
I had also tried adding android:configChanges="orientation|screenSize" to my activity within the androidmanifest.xml but to no avail.
I just realized that adding android:configChanges="orientation|screenSize|keyboardHidden" only works when i am had not extended the class from the navigationdrawer and thereby making it a fragment with the navigationdrawer class. This only works when it is not in a fragment layout form.
You need to declare android:configChanges="orientation|screenSize" in activity tag not in application tag
<activity
android:name=".ApplicationsClass"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I'm an Android noob and I'm having difficulty finding out something basic about Android.
I currently have an activity_main.xml file.
I want to use this layout when I first start the Android emulator, using Android Studio
Does Android look for a file activity_main.xml and use it as the default layout?
Here's my AndroidManifest.xml:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
So I understand that this specifies that my .MainActivity will respond to an action.MAIN intent call. What I don't know is what the action.MAIN intent call actually is, and how my activity_main.xml relates to this.
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Can anyone provide an explanation or a link to a good primer that explains these basic concepts?
From manifest :
<action android:name="android.intent.action.MAIN" />
Means this activity is the entry point of the application. In your case, the MainActivity starts.
The MainActivity sets up the layout for itself - the line responsible is
setContentView(R.layout.activity_main);
Where it looks for layout file activity_main.xml. This is just the naming convention - feel free to rename the layout file and call the new one from setContentView. It's not required to be called activity_main
I have an activity, which is launched every time user wants to unlock a phone (MainActivity).
I wish to add another activity to the app, which will launch every time user clicks an icon of an app, and will contain settings for the first activity. What is the correct way to set it in AndroidManifest.xml?
Currently my AndroidManifest file looks like this:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".BootCompletedReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name=".LockService"></service>
</application>
Define your activity in manifest like following:
<application>
...
<activity android:name=".YourNewActivity"></activity>
...
</application>
P.S:I assume that you activity is directly under the outermost package. if there are sub packages then you might need to use .subpackagename.YourNewActivity.
Now in your MainActivity, define a button inside who's onClickListener, you can start your second activity YourNewActivity using `Intents'. You might want to see this
How to start new activity on button click . Hope this helps.
You can't tie an activity to a button click in the UI inside the manifest file itself. Just add a normal <activity> and then ask for that activity to be called when you click the button.
The whole purpose of activities is that they can be re-used when the user opens the application again. You could create one activity and create a fragment everytime you open your app. Fragments do not have to be declared in your manifest. Your activity keeps track of the data. You are trying to add something dynamicaly (a unknown amount of activities) in a static xml-file (your manifest).
Just create a new fragment in your activity's onResume method.
http://www.vogella.com/articles/AndroidFragments/article.html
I'm trying to create a simple app, whose main task is to open the browser on defined URL.
I've created first Activity:
public class MyActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
Intent myIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://my.url.tld"));
startActivity(myIntent);
}
Here's my AndroidManifest.xml:
<manifest ...>
<application ...>
<activity android:name=".MyActivity" ...>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
This code is fully functional, but before it opens the browser, it displays a black background - blank app GUI. I didn't figured out, how to go directly do the browser (without displaying the GUI).
Anyone knows?
Add this theme declaration to your activity definition in you manifest
<activity android:name=".MyActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar"
>
Be careful with this, you must call finish(); from your activity after you are done with it otherwise users could get stuck with an invisible activity that prevents them from interacting the phonetop.