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.
Related
So I programmed an NFC tag to launch my application that I'm currently working on. I used the following service to do that:
https://play.google.com/store/apps/details?id=com.wakdev.wdnfc&hl=en
What I want to do is to switch from one activity to another whenever the NFC tag opens my application.
Under the manifest tag in my AndroidManifest.xml I have:
<uses-permission android:name="android.permission.NFC" />
<uses-sdk android:minSdkVersion="10"/>
<uses-feature android:name="android.hardware.nfc" android:required="true" />
And my MainActivity looks like this:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
Since the NFC tag opens the MainActivity first, I want to see whether it's been opened by NFC. If it has, switch to another activity.
The problem is that getIntent().getAction() always returns android.intent.action.MAIN while I'm expecting android.nfc.action.NDEF_DISCOVERED.
At the moment I'm performing this check (debugging basically) under onResume() method with the following code:
#Override
protected void onResume() {
super.onResume();
System.out.println(getIntent().getAction());
}
And I've tried performing this check under onCreate() and onStart() methods. All of them return android.intent.action.MAIN result while I expect android.nfc.action.NDEF_DISCOVERED.
I'm fresh in Android development and I'm just trying to make this work for a small prototype. Would appreciate if you guys could help me!
Edit: I got it working! I researched this question a lot and I believe that my NFC tag needed some extra data of a text/plain type (I did not specify this mimeType before as well so seems like it's mandatory). I also had put NDEF_DISCOVERED under LAUNCHER category while trying to debug the application and then changed it back to DEFAULT. I'm finally getting my desired results!
getIntent() returns the Intent that was used to create the activity. In your case, that is the home screen launcher Intent.
When you scan the NFC tag, a new Intent will be delivered to that activity. That Intent is passed to an onNewIntent() method that you can override.
Depending on how your activity is being used, you might need to handle both cases:
Where the user launched your app by scanning the NFC tag, so your activity was created with the NDEF Intent
Where the user launched your app by other means before scanning the NFC tag, so your activity was created with some other Intent and you get the NDEF Intent in onNewIntent()
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 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
I'm doing an Android project on Eclipse and I have 2 independent apps sources(Modules). How do I combine these two modules, such that when a button (present on first app) is clicked, the second app is launched?
As far I've just created the button and that's it.Any Help would be appreciated.
As I'm a beginner, please be specific :) Thank you!
In the manifest of the second app :
<activity
android:name=".MainActivitySecondApp"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.external.intentReceiver" />
</intent-filter>
</activity>
And then place the following code inside the onClickListener of the Button in the first App :
Intent intent = new Intent();
intent.setAction("com.external.intentReceiver");
context.startActivity(intent);
So, when the button is clicked, an intent of the type com.external.intentReceiver will be fired. The MainActivitySecondApp will then open since it is meant to handle such intents as defined in the Manifest.
I am new to Android and I copied a sample code from web and build my app on that sample code. But I am trying to delete the image on the top toolbar. I cannot locate where the program puts that image.
here is the screen. I put a red mark on the toolbar I am talking about and I want to remove that smily face on that bar. but I dont want to delete the image, I want to find the code which puts that face there.
That will be located in your manifest file under the <application> tag. Here is an example:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
Now each of the ="#somewhere/name" is a pointer. The icon is under res/drawable, while the other two will be under res/values/
You can use the following code. You must add in the onCreate() method of your activty :
getActionBar().setDisplayShowHomeEnabled(false);