No Activity found to handle Intent - android

I know that there is a lot of questions related to this issue, but none of them solve my problem. I made a quiz app with 50 questions fragments. In the final question (Question 50 fragment) I call the score Activity to show the score. In this Activity I created a "Play Again" button, which calls the Main Activity again to start the game. But everytime I click on "Play Again" button, my app crashes.
Logcat error: 04-03 15:34:43.638 26316-26316/com.example.moresche.englishqigame E/AndroidRuntime: FATAL EXCEPTION: main
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.moresche.englishqigame.MainActivity }
scoreActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_score);
Typeface mTypeface = Typeface.createFromAsset(getAssets(),"chlo.TTF");
TextView myTextview = (TextView)findViewById(R.id.txtla);
myTextview.setTypeface(mTypeface);
Typeface m2Typeface = Typeface.createFromAsset(getAssets(),"chlo.TTF");
TextView m2yTextview = (TextView)findViewById(R.id.txtla1);
m2yTextview.setTypeface(m2Typeface);
initControls();
}
public void initControls() {
TextView final_score = (TextView) findViewById(R.id.textView103);
TextView final_scoreqi = (TextView) findViewById(R.id.textView104);
TextView lvlqi = (TextView) findViewById(R.id.textViewzzz);
Button btnxd = (Button)findViewById(R.id.btnx);
final SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(this);
...
btnxd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
app_preferences.edit().clear().commit();
Intent intent1 = new Intent ("com.example.moresche.englishqigame.MainActivity");
startActivity(intent1);
}
});
Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.moresche.englishqigame">
<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"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".scoreActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.example.moresche.englishqigame.scoreActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>

You are calling your intent in the wrong way.
Intent intent1 = new Intent ("com.example.moresche.englishqigame.MainActivity");
It should be something along the lines of:
Intent intent1 = new Intent(scoreActivity.this,MainActivity.class);
http://developer.android.com/training/basics/firstapp/starting-activity.html
Although that will only taking you to the page not play the game again.

Related

app unfortunately stopped when use "Intent intent = new ...." method to change screen

I have created a simple app.
one screen of my app has following code and I use a Button (id "sendManual") to change the app view to another one.
please look at the end of this code, you can seen the button id "sendManual".
I have setup it to change screen view to App2Activity.java
(I have put the Code of App2Activity java below this code, then you can check it also)
I installed this app on my android phone, But when I click Button(id"sendManual") app suddenly Stopped and says
Unfortunately,XXXXX app has stopped
public class showPermission implements View.OnClickListener {
Dialog dialog;
Activity activity;
public void showDialog(final Activity activity){
dialog = new Dialog(activity);
dialog.setCancelable(false);
this.activity=activity;
dialog.setTitle("XXXXX");
dialog.setContentView(R.layout.permission);
Button Sendcancel = (Button) dialog.findViewById(R.id.sendCancel);
Button SendNow = (Button) dialog.findViewById(R.id.sendNow);
Button sendManual = (Button) dialog.findViewById(R.id.sendManual);
sendManual.setOnClickListener(this);
SendNow.setOnClickListener(this);
Sendcancel.setOnClickListener(this);
dialog.show();
}
#Override
public void onClick(View view) {
int id=view.getId();
if(id==R.id.sendCancel){
dialog.dismiss();
}
else if(id==R.id.sendNow){
sendSMS();
}
else if(id==R.id.sendManual){
Intent intent = new Intent(activity, App2Activity.class);
activity.startActivity(intent);
}
}
Here is the code of App2Activity.java
public class App2Activity extends Activity {
Button button;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
findViewById(R.id.start).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
sendSMS2();
}
});
}
............ etc
Here is manifest file.
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="16" />
<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>
</application>
You are not properly set context in Intent.Use this
Intent intent = new Intent(getApplicationContext(), App2Activity.class);
startActivity(intent);
instead of
Intent intent = new Intent(activity, App2Activity.class);
activity.startActivity(intent);
This all is happening because you didn't declare App2Activity in Manifest.xml. That is compulsory to declare all the activities in manifest file.
Replace your manifest.xml with this one:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="16" />
<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>
<activity android:name=".App2Activity"/>
</application>

Android Intent Declaration troubles

I am trying go from one activity to its sub-activity (i.e, a new page with more buttons), but every time I click the button, the application "Unfortunately stops running".
I believe that the flaw lies in the manifest where I might writing something wrong under the intent-filter section.
Mind taking a look?
public class MainActivity extends ActionBarActivity {
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
addListenerOnButton2();
}
//First Activity
private void addListenerOnButton() {
// TODO Auto-generated method stub
button = (Button) findViewById(R.id.activity_one);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent IntentOne =
new Intent(arg0.getContext(), ActivityOne.class);
arg0.getContext().startActivity(IntentOne);
}
});
}
//Second Activity, will look into it later. Making it Explicit for now.
public void addListenerOnButton2() {
button = (Button)findViewById(R.id.activity_two);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View argo) {
Intent IntentTwo = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.ca"));
startActivity(IntentTwo);
}
});
}
}
///////////////////////////////////////////////////////
Here is the Manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.poop"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.poop.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>
<activity
android:name="com.example.poop.ActivityOne"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.poop.ActivityOne" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
I have not added ActivityTwo yet to the manifest.
You can't have Activities that aren't registered in the Manifest. I don't see an ActivityOne registered in your AndroidManifest.xml

Activity not started

In my OnClick event attached to an imageview, I want to open a new activity with a screensized imageview on it to show the picture.
This is the event:
public void onClick(View arg0) {
PhotoList pli = (PhotoList) arg0.getTag();
Intent i = new Intent(getBaseContext(), PhotoActivity.class);
i.putExtra("photo", pli.Photo);
i.putExtra("PhotoId", pli.id);
getBaseContext().startActivity(i);
}
This code is being executed when I click on the image, but nothing happens.
The onCreate of PhotoActivity (which is never executed):
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photo);
getActionBar().setDisplayHomeAsUpEnabled(true);
Bundle extras = getIntent().getExtras();
photo = extras.getByteArray("photo");
ViewId = extras.getInt("View");
PhotoId = extras.getInt("PhotoId");
if (photo.length > 0) {
ImageView iv = (ImageView) findViewById(R.id.pvPhoto);
Bitmap mBitmap = BitmapFactory.decodeByteArray(photo, 0, photo.length);
iv.setImageBitmap(mBitmap);
}
The manifest:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="enn.com.sitefinder.MainActivity" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".PhotoActivity"
android:label="#string/title_activity_photo" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="enn.com.sitefinder.MainActivity" />
</activity>
</application>
When I accidently connected the OnClick eventlistener to the linear layout, the activity did start.
Why is the activity not shown?
Solved it by passing on a extra integer in the extras, allowing the PhotoActivity class to find the image in the arraylist.
This instead of passing the bitmap byte array which is too much for the bundle.
you do not need to use getBaseContext.startActivity
just use startActivity(intent);

android intent filter?

I'm feeling stupid.This is very clear but I can not solve my problem.So excuse me for my question.
My problem is in about intenfilter.This is application tag of my manifest file:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".AlakyTestActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="reza"
android:name=".A2" >
<intent-filter >
<action android:name="MAIN" />
<category android:name="LAUNCHER" />
</intent-filter>
</activity>
</application>
And this is my button click listener:
b1 = (Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent2 = new Intent();
intent2.setAction("MAIN");
intent2.addCategory("LAUNCHER");
startActivity(intent2);
}
});
I think that all things is good but when I run my code and click on b1,I get this erroe:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=MAIN cat=[LAUNCHER] }
Edit:
This is A2:
public class A2 extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main2);
}
}
Please help me.
You should set the android:name of the second activity to the (package name).(the class)
for example, lets say the second activity class is 'com.my.app.reza' you should add you the manifest:
<activity
android:label="#string/app_name"
android:name=".reza" >
<intent-filter >
<action android:name="com.my.app.REZA" />
<category android:name="android.intent.category.DEFUALT" />
</intent-filter>
</activity>
and you should start the activity like that:
Intent intent = new Intent("com.my.app.REZA");
startActivity(intent);
NOTE that it isn't the best way to do it, you shouldn't mess to much with package name I'd recommend you to do it the following way:
<activity
android:label="#string/app_name"
android:name=".reza" />
and start it like that:
startActivity(new Intent( this.getContext() , reza.class );
Please use like that:
Intent intent2 = new Intent(context,A2.class);
startActivity(intent2);
android:name=".A2" ,you must have "A2" activity class implement!
Modify to android:name=".A2", not android:name="A2"!
You don't need to specify category if you just need to call A2 inside your app. And you should set an unique action name, for example it can be a hash string:
...
Intent intent2 = new Intent("a202bfa923069ee8e119205e3468ee131ceafda37");
startActivity(intent2);
Note that action name uses same rule as package name.
<intent-filter>
<action android:name="com.blacky.basictutorial.TutorialTwo" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Try to use this in your second activity and call by the following code:
startActivity(new Intent("com.blacky.basictutorial.TutorialTwo"));
Hope this will work for you.

Nothing happens on startActivity()

I have 2 activities with a few buttons etc. I want to start new activity. I have done everything the tutorial said, but the 2nd activity does not start!
case R.id.btnIstorija:
Intent i = new Intent (this,KlasaPrikazBaze.class);
startActivity(i);
break;
It should start my 2nd activity
public class KlasaPrikazBaze extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.prikazbaze);
TextView TV = (TextView)findViewById(R.id.tvSQLinfo);
KlasaBaze info = new KlasaBaze(this);
info.open();
String podatak = info.DohvatiPodatak();
info.close();
}
}
However nothing happens.
Manifest:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".TalentiFinalActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".KlasaPrikazBaze"></activity>
</application>

Categories

Resources