I'm building an AndroidApp which uses a java-class Question.java which extends android.app.Activity.
The Activity is stated in the androidmanifest.xml as
<activity
android:name=".gui.android.Question"
android:label="#string/question_activity" >
</activity>
While using this version I get an ActivityNotFoundException: Unable to find explicit activity class everytime I try to start this activity.
However, after hours of not getting any further i tried to make a new Java-Class QuestionFix.java plus a new Activity
<activity
android:name=".gui.android.QuestionFix"
android:label="#string/question_activity" >
</activity>
The code of Question.java and QuestionFix.java and calls are 100% equal except the startActivity-calls.
Using the QuestionFix.java-Class causes no problem at all and everything works as expected.
I tried deleting Question.javaand then replacing it QuestionFix.java but the error persisted. Using a FQN in the androidmanifest.xml didn't help.
Is someone able to tell me how I can fix this?
Related
I am new to App Development and I've been studying Kotlin for only a month now (1 hour everyday). I got the grasp of the functions but I still haven't gotten around using them for the purposes I have in mind.
Using Android Studio, I am trying to make the App load into a logo upon opening the app(Just like Facebook, Reddit), the logo is animated (which is not a problem for me). I have a couple of ways to achieve this but I wanna see what's the most efficient way to do it.
Create a new SplashActivity and change your starting activity in you manifest file like this:
<activity
android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
then in your SplashActivity's OnCreate, start your MainActivity
startActivity(Intent(this, MainActivity::class.java))
You can read more about this here.
You can create one Activity let's say SplashActivity which will have your logo and animations you want. Then from that Activity you can start your MainActivity. If you need to process some data inside your SplashActivity you do that then you start MainActivity. Otherwise, if you don't have any data to process you can simply start MainActivity with some delay, like this:
Handler().postDelayed({
val i = Intent(this, MainActivity::class.java)
startActivity(i)
}, 5000)
This will start your MainActivity after 5000 milliseconds which is 5 seconds. Now try to write some code and if you run into a problem try to find a solution or ask again if you can't. There is a lot of tutorials on the Internet you can find on how to do this.
Good morning,
Quick coding inquiry I'd like to put forth.
I've gotten an assignment to produce an application on Android Studio that has two buttons that should each load new pages when clicked.
The chapter from our books explains how to do this with one button, but I assume there might be a different set up with two buttons?
Anyway, this is only the second assignment in our class so I'm not very far in understanding how all of this works; that and the class is an Independent Study course so I'm teaching myself. Not always the easiest thing.
Anyway, here's what I do have:
MainActivity.java
package com.example.thelatestmusicscene;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.buttonOne);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, MusicNewsOne.class));
}
});
Button button2 = (Button) findViewById(R.id.buttonTwo);
button2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, MusicNewsTwo.class));
}
});
}
}
I believe this is the only file that's relevant to my problem but I can post the others if you need to see them too.
The first button functions perfectly but when I try to use the second button the app stops working. I've seen a few explanations online, but the few I've found about loading other pages gives me a bunch of errors in my code.
Note: This is how we were shown to do it from the book, but I'm all for alternative methods.
Everything else for this application is done, it's just this linking to the second java page I'm faltering on. If you know a better way to lay out the code I'm all ears or if you could link me to a resource that could teach me, I'd be grateful.
OK, this is going to be the confusing part. When I downloaded Android Studio for the class I could never get any of the emulators to run. This was a problem I also posted, which as of today, has still not received an answer. If you have a solution to that or want to see those details of what I’ve tried, go here:
https://superuser.com/questions/1394568/android-studio-and-haxm-installation
Ultimately, I could write code, but I couldn’t test it. However, I found a way to run the apps on my own smartphone to test if they’re functioning. Letting Android Studio build the APK file and then letting my phone run the app.
Now…as for errors. There are none. Android Studio isn’t coming back with any. As far as it's concerned, everything is fine. When I load the application on my phone and I click the second button, the application closes, and I get “Unfortunately, nameOfApp has stopped.”
And that’s where I find myself.
Here’s the XML (I assume you mean the AndroidManifest.xml)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.thelatestmusicscene">
<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=".MusicNewsTwo">
</activity>
<activity android:name=".MusicNewsOne" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I've got to get some sleep now but I'll try retrieving a crash report from my phone today if I can.
Brother your MainActivity.java file have correct code.
Kindly check button name in xml and java file, and check your manifest file either MusicNewsTwo added as activity.
And be sure you have both java and xml file in correct place.
Few notes
You may need to provide the crash's log/stacktrace/message (for us to know what's the solution for it)
You may also need to provide us the layout or the .xml file
What could possibly went wrong
One of the common problems encountered:
Assuming you have only copied it from your class, you might have encountered the error saying that your MusicNewsTwo.class is not declared in the AndroidManifest.xml, do this:
What could be the possible solution
<application
android:label="Example APp"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name="package.path.to.MusicNewsOne">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Add this activity if missing -->
<activity
android:name="package.path.to.MusicNewsTwo"/>
</application>
I will update my answer so as long as you take into consideration the Few notes section of my answer, otherwise if I got your answer write already with this one, comment out.
Found the problem within my phone itself. Turns out it was a permission error for downloading 3rd party apps; my code was actually perfect. Thanks for all the suggestions though.
I think the IDs of the views in the layout : "activity_main" are different than the ones you are using in the MainActivity.java file
Bro there are two ways to do this, start a new Activity like you are doing, and other is By Using one activity you can post the fragments on the same activity as much as you want i.e 1 ,2 3 and so on.here is the link for fragments, but you are very much biggner ill suggest you to start with the actitvity and learn about the Activity life cycle. you can find here . moreover tell me what the error you are getting, To find the error see a the bottom of android studio the option (Logcat) click on it . and see the error and past it in the comment.
Here is my source code of launcher activity.
I search a lot on stack overflow but nothing getting good answer
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_lang);
init();
}
private void init(){
spnLanguage = (Spinner)findViewById(R.id.spnLanguage);
btnNext = (Button)findViewById(R.id.btnNext);
btnNext.setOnClickListener(this);
}
Android apps do take some amount of time to start up, especially on a cold start. There is a delay there that you may not be able to avoid
https://www.bignerdranch.com/blog/splash-screens-the-right-way/
In the AndroidManifest file of your starting Activity, mention a transparent Theme
<activity
android:name="Your activity name"
android:theme="#android:style/Theme.Translucent.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
In my case delay was bit more. After searching a lot I found that it is because of android studio auto run feature. After disabling the auto run issue is solved.
I had a similar problem some time ago.
The activity is displayed to the user when it reaches the onStart() method. Your init() seems to take some time so until it finishes, you will only see the empty activity.
You could either trigger all heavy background work (that is not needed for the initial GUI setup) in a later method or first call another activity acting as splash screen if you have to keep all content of init() where it is.
I had also same issue please find below the question as well as the resolution:
White screen is displayed first time on gradle build.
I've been following the ParseLoginUI tutorial here: https://github.com/ParsePlatform/ParseUI-Android/tree/master/ParseLoginSampleWithDispatchActivity
In my AndroidManifest.xml, I have:
<activity
android:name="com.parse.ui.ParseLoginActivity"
android:label="#string/app_name"
android:launchMode="singleTop">
<meta-data
android:name="com.parse.ui.ParseLoginActivity.PARSE_LOGIN_ENABLED"
android:value="true"/>
<!--<meta-data-->
<!--android:name="com.parse.ui.ParseLoginActivity.PARSE_LOGIN_EMAIL_AS_USERNAME"-->
<!--android:value="true"/>-->
<meta-data
android:name="com.parse.ui.ParseLoginActivity.FACEBOOK_LOGIN_ENABLED"
android:value="true"/>
<!--<meta-data-->
<!--android:name="com.parse.ui.ParseLoginActivity.TWITTER_LOGIN_ENABLED"-->
<!--android:value="true"/>-->
</activity>
...and:
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="#string/parse_app_id" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="#string/parse_client_key" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
In my GlobalApplication class, I have:
ParseFacebookUtils.initialize(this);
I realize this looks like a hash key problem, but I've tried hashing and re-hashing using various methods found here: Key hash for Android-Facebook app
I'm hoping it's not something as trivial as messing up my hash keys, because I've triple checked these. Is there something wrong with my code?
What is the problem here? See attached image below:
(source: elgami.com)
I figured it out! Hopefully this helps others as well. There was nothing wrong with the way I generated the hash keys. I just wasn't using a signed release build while testing for the Facebook hash. Make sure you generate a signed APK, copy the APK into your phone and install it, then open the app. When you attempt to login with Facebook you will still see the error, but displayed will be the correct hash key, and you will want to add this exact value into your Facebook app dashboard as your production hash!
I am attempting to enable Bluetooth on an Android device. I have read to Android documentation and have a pretty good idea of what the process is. I am, however, rather stuck at actually firing off an Activity using the manifest file. This is what I've done so far...
I've developed an Android Module with a couple of classes:
BluetoothModule // extends KrollModule
BluetoothSetup // extends Activity
In BluetoothSetup, the onCreate method looks like:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
connectBluetooth();
}
Also in BluetoothSetup, the connectBluetooth() method looks like:
protected void connectBluetooth(){
// if statements to check if bluetooth is enabled/avail removed
Intent intentBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(intentBluetooth, 0);
}
}
Finally, in the module's timodule.xml I've added:
<activity android:label="#string/app_name" android:name="com.eyesore.bluetooth2.BluetoothSetup">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
The module compiles just fine, but does not actually do anything. I fear that I've missed a fundamental step here, but I'm just not sure what it is. Any advice would be greatly appreciated!
Figured this out. Wound up creating a custom per instructions here:
https://wiki.appcelerator.org/display/guides/Maintaining+a+Custom+AndroidManifest.xml
I removed the extra code Titanium drops in the manifest file and it seems to be working.