I am trying to change screens from the first to second and back again, but with some extra variables passed. At the moment I go from 1 to 2, but when I click from 2 back to 1 it causes an error that the application stopped unexpectantly. I have issolated the problem to this part of the code. I'm not at the moment trying to pass any other variables with it just get it to change.
1st page package = max.multiplebuttons.com
Activity = multibuttons
1st page package = max.reason.com
Activity = reason_screen
public void nextquestion(){
Intent a = new Intent();
a.setClassName("max.reason.com", "max.multiplebuttons.com.multibuttons");
startActivity(a);
}
a.setClassName("max.reason.com", "max.multiplebuttons.com.multibuttons");
Your problem is here. The class multibuttons isn't inside the package max.reason.com.
Edit:
I can't give you the exact syntax because I need to see the naming conventions, but you have to do something like this:
Intent a = new Intent(Activity1.this, Activity2.class);
startActivity(a);
Related
I have an Activity1 which launches Activity2. Activity2 has a list which shows some values from database.
When the Activity2 is launched for the first time the list shows the correct information, but if I press back button and then launch the Activity2 again it loads the information correctly from database but it's not displayed on the list.
The code to start Activity2 from Activity1:
final Intent int2 = new Intent(getActivity(), CombinationsManagerActivity.class);
MyActivity.insertSomeExtraInfoToTheIntent(int2, currentEmployee.id);
getActivity().startActivity(int2);
And the Activity2 list code is this (I call it when the activity is register with a server (after onResume)):
private void fillList() {
list = (ListView) findViewById(R.id.list_combinations);
ZKEmployeeLoginCombination combinations = ZKEmployeeLoginCombination.selectLoginCombinationsByEntityID(this, idEmployee);
LoginCombinationsListAdapter adapter = new LoginCombinationsListAdapter(this, combinations, enrolledTypes);
list.setAdapter(adapter);
}
Also, Activity2 manifest declaration:
<activity
android:name="com.blabla.android.app.employeemanagementv3.CombinationsManagerActivity"
android:label="#string/combinations_manager" >
</activity>
Any help would be appreciated.
Finally I found the bug on my code: For project requirements we keep some structures to act as listeners from server events. And registration was one of them.
The way to register the listeners from the activity was:
private static IncomingEventHandler eventHandler = new IncomingEventHandler();
...
if(eventHandler.get(this.name) == null){
eventHandler.add(this.name, this);
}
So I was keeping the reference from the previous activity, and then, when the activity receives a registration event we were doing in post:
referenceToActivity.doSomeStuffOnUIThreadAfterRegister();
This works well the first time, but in the second execution referenceToActivity were pointing to the first activity
You probably only ever want there to have one Activity2 alive in the app. If so, I suggest that you include the following in the manifest for Activity2
android:launchMode="singleTask"
That may solve your problem. For an explanation, see the android documentation.
Just give a try by putting this code snippet on your Activity2 class
#Override
public void onBackPressed() {
Intent startNewActivityOpen = new Intent(Activity2.this, Activity1.class);
startActivity(startNewActivityOpen);
}
I need some help with using integer from one activity to another.
I am making some basic math program(game). It gets two random numbers, random operator, and 30 secs to solve math problems as much as you can.
If you solve problem u get 1 point.
Anyway right now, I want to get number of points that user have made and use it in another activity called *RankActivity*.
Main activity is called *BrzoRacunanjeActivity* and it contains button and one *int* called *poenibrojanje* which get number of points that user have made, and when I click on button, it opens new Activity with this line:
startActivity(new Intent(this, RankActivity.class));
As you can see another Activity is called RankActivity, and there I wrote :
*BrzoRacunanjeActivity a1 = new BrzoRacunanjeActivity();*
*System.out.println("Number of points:" + a1.poenibrojanje);;*
and I get all time this reuslt: 09-22 09:09:14.940: INFO/System.out(289): Number of points:0
Try this:
Intent intent = new Intent(this, RankActivity.class);
intent.putExtra("points", pointsVar);
startActivity(intent);
In onCreate of RankActivity:
getIntent().getIntExtra("points", 0);
so you want to pass integer value from one activity to another activity? right...
try:
Intent intent = new Intent(currentclass.this, destination.class);
intent.putExtra("point", pointvalue);
startActivity(intent);
at destination activity:
final int getpoint = getIntent().getExtras().getInt("point");
This will solve your problem.
first of all make
static variable like as public static int poenibrojanje;
in your BrzoRacunanjeActivity.class file now you can use this variable in any other class like as
BrzoRacunanjeActivity.poenibrojanje
or you can use putExtras(); method.
in you main activity.
Intent i = new Intent(this, RankActivity.class);
i.putExtra("Value",poenibrojanje);
in your next activity
int v = (getIntent().getExtras().getInt("Value")) ;
I need help doing something that I am sure is simple, but I can't figure out how to do it. I have a counter down and when it gets to the last 60 seconds, it calls a 'lastminute' counter activity. The plan is to overlap the last 60 seconds over the actual application.
Here is the problem, how can I change the code to allow the two activities to start at the same time.
I have tried this;
public void onFinish() {
startActivity(new Intent ("eu.merso.phoneapp.LASTMINUTE"));
startActivity(new Intent ("eu.merso.phoneapp.DASHBOARD"));
onDestroy();
}
but this does not put both applications on the screen, what I want is DASHBOARD on the background and LASTMINUTE on top. LASTMINUTE is alreay a "transparency colour".
Thanks;
Ramón
It won't work the way you're currently trying to do it. There can only be one visible activity at a time.
You should first start the dashboard Activity and from there you should start lastminute.
Edit --
Use a Bundle object.
Bundle bundle = new Bundle();
// Use 0 when the activity is called by the button and
// 1 when it is called by the timer.
bundle.putInt("event_src", 0);
intentObject.putExtras(bundle);
// In your new activity you can then check whether to display
// the countdown or not
Int eventSrc = getIntent().getExtras().getInt("event_src")
You need to implement the lastminute functionality in a dialog that you create and show in the onCreate method of your dashboard activity.
EDIT:
To distinguish between which activity that starts the new activity, use intent extras:
//in your calling activity
Intent i = new Intent(A.this, B.class);
i.putExtra("from Activity", A.class.getSimpleName());
startActivity(i);
//in your receiving activity
String from = getIntent().getStringExtra();
if(from.equals(A.class.getSimpleName())){
//do something
}
else if(from.equals(C.class.getSimpleName())){
//do something
}
Try using android:theme="#android:style/Theme.Translucent.NoTitleBar in Activity attributes for LastMinute in AndroidManifest.xml. I hope it'll be productive.
I think using Android fragments will help u to show two separate activities in the context of another main activity.
try reading this:
http://developer.android.com/guide/components/fragments.html
Android 2.1 update 1
Eclipse 3.5
I have a problem reading data from my 2nd activity that is called from the 1st activity using intent. I have androidmanifest.xml setup correctly.
My First Activity has the following code:
Intent myIntent = new Intent(MainMenu.this, Testmenu.class);
myIntent.putExtra("com.tweaktool.MyAge",40);
myIntent.putExtra("com.tweaktool.Enabled", false);
startActivity(myIntent);
My 2nd Activity has the following code:
Bundle bun = getIntent().getExtras();
int myAge = bun.getInt("MyAge");
boolean enabled = bun.getBoolean("Enabled");
When I look at the above code in 2nd Activity it lists the following:
enabled = false
myAge = 0
Why is this doing this??? Am I doing something simple wrong??
You're putting data with one keys ("com.tweaktool.MyAge", "com.tweaktool.Enabled") and trying to get it with others ("MyAge", "Enabled") -- the bundle then just returns you defaults (0, false). To get what you've put, use the keys you've used.
Have your tried
int myAge = bun.getInt("com.tweaktool.MyAge");?
I want to know how to move from one class to other class in android.
I have one main class i.e Addition.java(Main Activity) and i created other subactivity(Form.java).
I want to how to make my move from one class(ie.Activity)to other.
I tried this,but not working out,just trying to figure out
Intent intent = new Intent();
intent.setClass(this.getParent(),Form.class);
startActivity(intent);
here Form.class is the subactivity, this.getParent I hope it represents main activity. And I created one activity in manifest.xml file and named it as .Form
Am i working right?
The below code works perfectly.
Try it:
#Override
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(v.getContext(),Form.class);
startActivity(intent);
}
make sure that activity is declared in Android.manifest.