I wrote a simple app involving two activities. I used an explicit intent to call the second activity, but it always force closes the app when I try to do so.
Code of 1st activity
public class Splash extends Activity implements OnClickListener {
private ImageButton ibLogo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
ibLogo = (ImageButton) findViewById(R.id.imageButton1);
ibLogo.setOnClickListener(this);
}
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new Intent(Splash.this, Menu.class));
}
}
Menu is in the same package as Splash
Android Manifest:
<activity
android:name="com.rakeshsarangi.petrofiesta2013.Menu"
android:label="#string/title_activity_menu" >
</activity>
I have seen other threads like this but none could help me. Really baffled at this simple thing.
It probably thinks that the menu from the line startActivity(new Intent(Splash.this, Menu.class)); is android.view.Menu. You should change the line to use the full name com.rakeshsarangi.petrofiesta2013.Menu.
Change -
startActivity(new Intent(Splash.this, Menu.class));
to -
startActivity(new Intent(Splash.this, com.rakeshsarangi.petrofiesta2013.Menu.class));
I thin it is taking Menu class from android.view
if you are extending Menu then this might be help full
as per commons-ware answer
You are trying to start an activity named android.view.Menu. You do not have an activity named android.view.Menu.
Intent myIntent = new Intent(getApplicationContext(), Menu.class);
If you change the second parameter of the Intent constructor to the Class object for your activity, that will likely work better. Even better would be to not have an activity named Menu, but to use something more distinctive, to help prevent this sort of collision in the future.
ActivityNotFoundException on launching class that is in manifest
Related
I'm new to android studio and i have a problem when I'm trying to jump to a new activity, so when the line is:
public class signup_activity extends AppCompatActivity {
ImageButton logupButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup_activity);
logupButton = findViewById(R.id.signuparrow);
logupButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, signup_activity.class);
startActivity(intent);
}
});
}}
I get the error:
'com.example.myapplication.MainActivity' is not an enclosing class
and i so a couple of of people advising to chane the intent to this instead of MainActivity.this
but when im changing to this i get the error:
Cannot resolve constructor 'intent'
Intent intent = new Intent(MainActivity.this, signup_activity.class);
Several things:
First, the first param of Intent() constructor is a context. Since you are on signup_activity you need to do signup_activity.this to use it as a context.
I'd assume you want to go to MainActivity, so your second param should be MainActivity.class. It seems you got the order altered there.
you are in signup_activity and when use Intent in fisrt part you should call the current contex to jump to other activity.
so you should replace
Intent intent = new Intent(signup_activity.this, MainActivity.class);
if you want to jump to signup_activity you can call intent from MainActivity.
I got a problem when I navigate between two activities, it shows me error and I don't know what is the problem. I am very sure that my code is correct, because it just simple Intent navigate by on click Button.
When I Press the button to go to the next activity it returns me to the fist activity (not the desire one). Note that both activity has background image.
Fist Activity
public class firstActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.first_activity);//has a background img and one button
}
public void nextPage(View view){
Intent StartNewActivity = new Intent(firstActivity.this, secondActivity.class);
startActivity(StartNewActivity);
overridePendingTransition(R.layout.slide_in_up, R.layout.slide_out_up);
}
}
Second Activity
public class secondActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_activity);// has a background img and one button
}
public void nextPage(View view){
Intent StartNewActivity = new Intent(secondActivity.this, thirdActivity.class);
startActivity(StartNewActivity);
overridePendingTransition(R.layout.slide_in_up, R.layout.slide_out_up);
}
}
This is the error message
Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
Also, I did not use any ripple drawable in my app.Even though I don't know what does it mean?
Thanks,
Something you have wants to to find a refwrence to that ripple component, you need to find out what.
Otherwise, you can try to make sure you have added a reference to the support.v7.widget in the second activity and see if the exception goes away.
Aside from that, we would need to see more code to help further.
When I Press the button to go to the next activity it returns me to the fist activity (not the desire one)
It means that your app crashes when loading your new activity, so it comes back the first one.
Check your activity layout, style configuration => clean your project => Run again.
Hope it can help.
I solved my problem by resizing the background images of the activities, and I added this extra attribute in the manifests file
<application
android:largeHeap="true" >
</application>
I have come across a strange error when i press a button that i supposed to return to teh main activity i get an activity not found error. But when i dod it from another activity, it works fine.
Working call:
final Button mainMen = (Button) findViewById(R.id.toMainMenu);
mainMen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),
Menu.class);
i.putExtra("Token", tok + teTok);
startActivity(i);
}
});
Broken Call:
maMenu.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(Campaign.this, Menu.class);
i.putExtra("Token", player.tokens);
// intent.putExtra("Round", player.round);
// intent.putExtra("Rank", player.rank);
// intent.putExtra("Score", player.score);
// intent.putExtra("Sec", player.secondsTapped);
// intent.putExtra("Min", player.minutesTapped);
// intent.putExtra("Hour", player.hoursTapped);
// intent.putExtra("Day", player.daysTapped);
// intent.putExtra("LifeTap", player.tapsInLife);
// intent.putExtra("SecTap", player.tapsPerSec);
// intent.putExtra("TapRo", player.tapps);
startActivity(i);
}
});
They are pretty much identical, but somehow the second one does not work. The first one has a bridging class before it. I looked through my xml file and nothing is wrong there since it works in one of my activities. The exact error i get is:
Unable to fin explicit activity class {com.tap.tapalot/android.view.Menu};
Thank You for Your help :)
I think you may have used wrong imports, so that Menu class is not the Menu-class you expect.
Try to specify the Menu.class in your intent with full package-path.
Check you seem to be importing. You are importing android.view.Menu in the second call. This is not your Activity class.
You are importing the wrong android.view.Menu class. You should import your Menu Activity class.
make sure you define 'Menu Class' in your mainfest file? like this:
<activity
android:name="pakgae.name.your.Menu"
android:label="#string/title_activity_menu" >
</activity>
Am creating small application using login, register and user details. After login am going to store login credential to shared preference and navigate to dashboard activity. In second time directly navigate to dashboard activity. This level of code is working fine.
Please consider I have three activity MainActivity, LoginActivity, RegisterActivity, DashboardActivity and ProfileActivity.
In my MainActivity If user value is sharedPreference directly moving to DashboardActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(new SessionManager(getApplicationContext()).isLoggedIn()){
startActivity(new Intent(getApplicationContext(), DashboardActivity.class));
}
}
In my DashboardActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ImageButton imgBtn = (ImageButton) findViewById(R.id.imageButton1);
imgBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(getApplicationContext(), ProfileActivity.class));
}
});
}
Now am simply press back button in device goes to MainActivity not DashboardActivity. I want to move activity to DashboardActivity only, not MainActivity. Please guide me how to do that. And how to handle session in Android.
Also I have bit confusion in using which flags and where to use. I tried in DashboardActivity but not working.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ImageButton imgBtn = (ImageButton) findViewById(R.id.imageButton1);
imgBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent newIntent = new Intent(getApplicationContext(), ProfileActivity.class);
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(newIntent);
}
});
}
Now I tried various possible ways but not getting solution.
Main problem occurs after navigating DashboardActivity to any Activity won't come back to DashbarodActivity instead of going MainActivity. I don't know why it happens. Any problem in MainActivity navigation
I'm not sure about that, but in DashboardActivity try to start your activity like this: startActivity(new Intent(DashboardActivity.this, ProfileActivity.class));
Just finish the current activity after starting the new one via Intent and you should achieve the desired functionality and this way you don't need any flags. Except for the MainActivity of course.
Just simply override onBackPressed method in your ProfileActivity and call finish method.
#Override
public void onBackPressed() {
finish();
}
EDITED ANSWER:
on your ProfileActivity, try to override onBackPressed method then start the DashboardActivity again and don't forget to finish the current activity.
#Override
public void onBackPressed(){
startActivity( new Intent(this, DashboardActivity.class) );
finish();
}
I'm new to Android Dev, so please help me out.
I'm trying to start a new activity after i press a button but nothing seems to work.
Here's my code:
public class viewInfo extends Activity {
private Button btn;
public TextView txt;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.info);
btn=(Button)findViewById(R.id.buy);
btn.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
Intent myIntent = new Intent(viewInfo.this, buyNow.class);
startActivity(myIntent);
}
});
}
I've also added this new activity in the Manifest but it keeps crushing after I press the button.
What am I doing wrong?
Misread the question initially (original answer below for completeness sake).
Make sure you have the activity you are calling defined in your manifest file:
Something like
<activity android:name=".buyNow" android:label="#string/app_name"></activity>
within the application tags would suffice.
Here's the original answer.
Assuming that you have the correct button ID - try this in your onclick:
Intent myIntent = new Intent(getApplicationContext(), buyNow.class);
startActivity(myIntent);
You could add a log message inside your onClick too, to make sure it is actually being called. You can see the log from logcat (run via adb logcat on the command line)
Try to make it:
startActivity(new Intent("[Here is your package name.what you declared in Manifest file]"));
For this you need to write to your manifest:
Hope it helps.
There may be a problem with your buyNow activity that is causing the error.
You really need to use logcat to trace the error. You can enable this by clicking the menu item:
Window -> Show View -> Other...
the selecting "LogCat" from the Android folder
You can simply do this:
startActivity(new Intent(getBaseContext(),Activity.class));
Afther you registred your activity in manifest:
<activity
android:name="com.example.ActivityName"
android:label="#string/app_name" >
</activity>