I have Starter ListActivity which starts two others: Multitouch and Accelerometer.
When the first one is touched in ListActivity it is launched very well.
The second one, however, isn`t laucnched.
Logcat reports:
06-09 22:42:55.293 12227-12227/com.mainpackage.api E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.content.ActivityNotFoundException: Unable to find explicit activity class
{com.mainpackage.api/com.mainpackage.api.Accelerometer};
have you declared this activity in your AndroidManifest.xml?
I have read related questions but they didn't help me out.
Starter activity:
public class Starter extends ListActivity {
private String[] tests = { "MultiTouch", "Accelerometer" };
#Override
public void onCreate(Bundle saved) {
super.onCreate(saved);
ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,tests);
this.setListAdapter(adapter);
}
#Override
public void onListItemClick(ListView list, View view, int position, long id) {
super.onListItemClick(list,view,position,id);
String test = tests[position];
try {
Class clazz = Class.forName("com.mainpackage.api."+test);
Intent i = new Intent(this,clazz);
startActivity(i);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mainpackage.api">
<application android:allowBackup="true" android:label="#string/app_name"
android:icon="#mipmap/ic_launcher" android:theme="#style/AppTheme">
<activity
android:name=".Starter"
android:label="#string/app_name"
>
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".MultiTouch"
android:label="MultiTouch" />
<activtiy
android:name=".Accelerometer"
android:label="Accelerometer" />
</application>
</manifest>
MultiTouch and Accelerometer have no bugs. I have tried them separate.
Any ideas ?
First, do not use Class.forName(). Either use if or a Class[] and just reference the Accelerometer.class and MultiTouch.class objects.
Second, your manifest has:
<activtiy
android:name=".Accelerometer"
android:label="Accelerometer" />
which has the element name spelled incorrectly. Try:
<activity
android:name=".Accelerometer"
android:label="Accelerometer" />
Related
It's my project situation now.
MainActivity is LAUNCHER
SplashActivity called MainActivity onCreate()
When I think about it, it looks like there is no problem.
but after app starting,
The MainActivity screen is briefly visible before SplashActivity call.
Surprisingly, I did not see it on other devices, only galaxy s8.
Of course, I know it is not a general structure. But I can not understand it because I have been working normally.
white color is cold start style and splashActivity.
red color is mainActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// some getIntent code
startActivityForResult(new Intent(this, SplashActivity.class), RESULTCODE_);
setInitLayout();
}
manifest
<activity android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SplashActivity"
android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme" >
</activity>
minSdkVersion 21
targetSdkVersion 28
If you use style with android:windowBackground for splash activity, don't call setContentView(). Thats all!
It is not a good idea to use a splash screen that way . This should be strictly avoided.
With this approach you may also lead the problem of blank white page appears during splash launching and this what exactly happened to you !
i advice you to read this article and try to make your splash screen in the right way to avoid such behavior !
You have placed MainActivity class to be the launcher activity in your manifest. I am assuming that your splashscreen activity is called SplashActivity. If you want it to be shown before as the SplashScreen and then MainActivity to come later on, change your manifest code to be:
<activity android:name=".SplashActivity"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme" >
</activity>
<activity android:name=".IntroActivity"
android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme" >
</activity>
Then create your SplashActivity as suggested by Ismail in the link that he has provided
simply add handler for limited seconds of time and finish current activity
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
//actvity transaction
}
},3000);
Use this thread code for splash activity it will better work -
public class SplashActivity extends AppCompatActivity {
private static int SPLASH_TIME_OUT = 3000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Thread thread = new Thread() {
public void run(){
try{
sleep(3000);
}catch (InterruptedException e){
e.printStackTrace();
}finally {
Intent mainAct=new Intent(SplashActivity.this, MainActivity.class);
startActivity(mainAct);
finish();
}
}
};
thread.start();
}
#Override
protected void onDestroy() {
super.onDestroy();
}
}
and your manifest class will be look like this :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.diskapp">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity android:name=".Activities.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activities.MainActivity" />
</application>
</manifest>
Use this thread code for splash activity. It will better work :
public class SplashActivity extends AppCompatActivity {
private static int SPLASH_TIME_OUT = 3000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Thread thread = new Thread() {
public void run(){
try{
sleep(3000);
}catch (InterruptedException e){
e.printStackTrace();
}finally {
Intent mainAct=new Intent(SplashActivity.this, MainActivity.class);
startActivity(mainAct);
finish();
}
}
};
thread.start();
}
#Override
protected void onDestroy() {
super.onDestroy();
}
}
I try to work with list view and on click open another activity but when I run the app on mobile it force stop. Below is my code for Main activity
public class MainActivity extends AppCompatActivity implements
AdapterView.OnItemClickListener {
String TopicList[]={"jan","Feb"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView=(ListView) findViewById(R.id.topic);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,TopicList);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position==0){
Intent myInternt= new Intent(view.getContext(),Vlookup.class);
startActivityForResult(myInternt,0);
}
if (position==1){
Intent myInternt= new Intent(view.getContext(),Hlookup.class);
startActivityForResult(myInternt,1);
}
}
}
Blockquote
Below my Maindest.xml file
`enter code here
<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>
<activity android:name=".Vlookup" />
<activity android:name=".Hlookup"></activity>
</application>
Replace this line from the code:-
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);
by:-
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,TopicList);
you are not adding list to adapter therefore it crashes,
And also check the manifest that the activity is added to it.
Make sure you have defined MainActivity, Vlookup and Hlookup in your manifest
<activity android:name=".MainActivity"/>
<activity android:name=".Vlookup"/>
<activity android:name=".Hlookup"/>
and replace
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);
by
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,TopicList);
I am trying to write a code that shows a list of apps and lets the user choose an app to delete. I wrote this code based on what i've seen online:
appListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Uri packageUri = Uri.parse(names.get(position));
Intent uninstallIntent =
new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
startActivity(uninstallIntent);
}
});
However, for some reason I am getting this exception:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.UNINSTALL_PACKAGE dat=com.ivuu }
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INSTALL_PACKAGES"
<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=".Main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AppList"></activity>
</application>
I am pretty new to android and I spent the whole day on this... Please tell me what I am missing
Thanks
You do not have a scheme. Your Uri needs to be of the form package:..., where ... is the application ID/package name.
I create a personnal component view and when we click on this, an other activity starts. There is my manifest.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.freshkamekentrainement.skrt">
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity android:name=".Splash"
android:theme="#style/Splash"
android:screenOrientation="portrait"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:screenOrientation="portrait"
android:configChanges="orientation"/>
<activity android:name=".niveaux.LilUziVert_GrowUp"
android:screenOrientation="portrait"
android:configChanges="orientation"/>
</application></manifest>
there is my intent
public class Niveauview extends RelativeLayout {
Intent intentNiveau;
//Code
#Override
public void onFinishInflate() {
super.onFinishInflate();
setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
intentNiveau = new Intent(MainActivity.this,LilUziVert_GrowUp.class);
startActivity(intentNiveau);
}
});
}}
I get error:
MainActity is not an enclosing class
Notice that NiveauView and MainActivity isn't in the same package (but they are public). Where does the problem come from? When i try new Intent(this,LilUziVert_GrowUp.class); i have an error too.
You can only access Foo.this if you're in a inner class of Foo. Otherwise you need to be passed in an instance of Foo instead. In the case of a View, every view has an instance of a Context you can get by calling getContext(). So you need to call intentNiveau = new Intent(getContext(),LilUziVert_GrowUp.class);
I'm trying to open a new activity using this code:
myListView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(Andro.this, Aktivity.class);
startActivity(intent);
}
});
The activity to be opened looks like this:
package com.andro;
import android.app.Activity;
import android.os.Bundle;
public class Aktivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState)
{
try
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
} catch(Exception e)
{
}
}
}
It is in the same package as the other activity, and in the same directory.
The manifest looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.andro"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="#string/app_name" >
<activity android:name="Andro"
android:theme="#android:style/Theme.NoTitleBar"
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=".Aktivity">
</activity>
</application>
</manifest>
I've tried with different names like '.Aktivity' '.com.andro.Aktivity' 'Aktivity' 'com.andro.Aktivity'
I delete the bin and gen directories before building.
But still I always get an Activity not found exception in logcat.
Any help is appreciated.
The logcat seems to be showing
com.andro.Andro$Aktivity not found
I think there is another class called Aktivity inside Andro class. So try using this
Intent in = new Intent();
ComponentName comp = new ComponentName("com.andro", "com.andro.Aktivity");
in.setComponent(comp);
startActivity(in);
Doesn't this work
<activity android:name="com.andro.Aktivity" ........ />
Can you try
<activity android:name=".Andro"
android:theme="#android:style/Theme.NoTitleBar"
android:label="#string/app_name">
instead:
<activity android:name="Andro"
android:theme="#android:style/Theme.NoTitleBar"
android:label="#string/app_name">
Edit:
It seems like a problem about your Andro Activity.
Unable to find explicit activity class {com.andro/com.andro.Andro$Aktivity};
If you are using a listview in your activity, make sure you extend "ListActivity" as:
public class Andro extends ListActivity
Try cleaning your project and restarting eclipse.