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
Related
I just need some information regarding the scope of execution. On my
To understand what is happening you need to know the Activity lifecycle
As you can see, when the app is launched, the first thing that's going to run is your onCreate() in this case, onCreate() has a method that inflates the view of your Activity, that method is called setContentView().
so, if you execute your code below setContentView, it will first inflate the view of MainActivity or the class you are in, and then just go to your other Activity.
If you want to start your Activity right when your app launches, just move your startActivity(...) above setContentView() in your onCreate(), but it will be better to do this in your manifest rather than just using a class to open another one.
To launch your WelcomeActivity just do this in your Manifest
<activity
android:name=".WelcomeActivity"
android:label="#string/app_name"
android:screenOrientation="sensorLandscape">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:screenOrientation="sensorLandscape"/>
<activity
So this
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
will define that WelcomeActivity executes first, then in WelcomeActivity do an intent to your MainActivity
Rather than load another activity within an activity, perhaps you should consider using a Fragment which are platform-defined modular sections of an activity with its own lifecycle and optional user-interface. See this for more info: https://developer.android.com/training/basics/fragments/fragment-ui
My advice would be to use support Fragments within your activity rather than 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.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
So basically I am creating a very simple app that has only 2 layouts and I want to go from one to another properly. I know from what I have read that if you want to create a new screen/activity on the same project, you first have to create the new layout (which I already did), and I know that now I have to create the activity and do something to the manifesto, but I do not know what that is. I have seem some youtube videos about but I do not know if the fact that if I want my new activity to be the default one changes anything.
As you will be able to see in the attached pictures, "activity_questions" was the first layout that I had back when I created the project. Now I want to create a new screen/layout for the app which is the "noquestions_layout" one. However, I want to make the new layout that I created my main screen/activity for the user, and my "activity_questions" the one that will pop whenever my database feeds some information to the app.
How can I do all this? I know this is one of the things that you only need to learn once...and this might sound very simple, and I apologize if is something newbie. I basically started to learn android studio not too long ago.
You do not need to tell me all the code that I need to put in my app, just some basic examples with guidance... "create Y here, and then put X there"
For new screen layout create a new activity and call that layout file there.
To make any activity as your first activity when app starts, you have to go to manifest and cut paste the intent filter tag to the activity you want to start first
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Suppose you want to make another activity example .SecondActivity as starting activity cut above intent filter tag and paste it there like this
<activity android:name=".SecondActivity ">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity ">
</activity>
First Create two Activities, Say, Activity_A and Activity_B.
For the first activity, place this code in the manifest:
<activity android:name=".Activity_A">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
For the second activity, use this code:
<activity android:name=".SecondActivity ">
</activity>
Here, the Activity that launches when the app starts is the Activity_A, because of the intent filter in the manifest of the Activity_A:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Now, Since you already have your Activities, the layouts ready, where Activity_A is started as soon as the app is started, to launch Activity_B from Activity_A, use this code:
Intent intentTour = new Intent(Activity_A.this, Activity_B.class);
intentTour.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); //This line is optional, better to use it because it won't create multiple instances of the launching Activity.
startActivity(intentTour);
When you create a new activity in Android Studio, Studio will create the corresponding resource file as well as manifest entry for your activity.
Say for example, you have two activities QuestionsActivity and NoQuestionsActivity. QuestionsActivity will be your default launch activity. To make NoQuestionsActivity your launch actvity. Open the manifest file and under activity tag of NoQuestionsActivity include the intent filter and remove intent filter from
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".QuestionsActivity"></activity>
<activity android:name=".NoQuestionsActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
To switch from one activity to another, say from NoQuestionsActivity to QuestionsActivity use intent the following code-
Intent questionsIntent = new Intent(NoQuestionsActivity.this, QuestionsActivity.class);
startActivity(questionsIntent);
If you want to pass value to QuestionsActivity pass it as extras in the intnet.
Hope this will help.
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.
In my program it adds a shortcut to the screen. I get the icon on the screen fine, but when I tap it, I get:
03-01 20:00:29.410: ERROR/AndroidRuntime(796): java.lang.SecurityException: Permission Denial: starting Intent { data=http://www.example.com/ flags=0x14000000 comp={com.isaacwaller.example/com.isaacwaller.example.ExampleCut} } from ProcessRecord{435c7398 796:android.process.acore/10005} (pid=796, uid=10005) requires null
Do you know the problem? Thanks,
Isaac
I had something like this happen when I had accidentally duplicated the activity tag for one of my activities in my manifest. I had something like this in my application section.
<activity android:name=".ConventionHome" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="ConventionHome"></activity>
When I removed the second activity tag, things started working normally.
Figured it out, added this under <activity> tag of activity:
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
</intent-filter>
Something like this should work:
<intent-filter>
<action android:name="com.example.Project.Action"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
inside of the Activity declaration in the manifest.
I ran into this problem too, and it turned out it was because the Activity wasn't exposed to other processes. I had to add the android:exported="true" attribute to the activity tag in my manifest.
See http://developer.android.com/guide/topics/manifest/activity-element.html#exported for more information.
I haven't run into this personally but I did do some research and found the following.
Apparently whatever is attempting to invoke your app or if your app has a call to create an intent and start an activity of some intent the UID is not the same.
In ActivityManagerServer.java there are below judgement in it.
int checkComponentPermission(String permission, int pid, int uid, int reqUid)
// If the target requires a specific UID, always fail for others.
if (reqUid >= 0 && uid != reqUid) {
return PackageManager.PERMISSION_DENIED;
}
I'm going to do some testing on this and see if I can reproduce this in a test application and provide any additional feedback.
Make sure you are only trying to invoke publicly exposed activities through any intents.