Android app seems hanging - android

I am trying to move from one activity to another activity. But some times seems it is hanging. On screen off and On it is working fine.
eg:
I am in Activity 1
Moved from Activity 1 to Activity 2
Seems it is hanged.
But if I do screen off and on it is on Activity 1.
Below is my Code sample:
Intent i;
i = new Intent(AdvSeatAvail.this, TrainsBetweenTwoStationsList.class);
i.putExtra("anim id in", R.anim.fragment_slide_right_enter);
i.putExtra("anim id out", R.anim.fragment_slide_left_exit);
i.putExtra("jsonvalue", jsonvalue);
i.putExtra("dateval", dateval);
AdvSeatAvail.this.finish();
AdvSeatAvail.this.startActivity(i);
overridePendingTransition(R.anim.fragment_slide_right_enter, R.anim.fragment_slide_left_exit);
Some one please help me to resolve this Issue.
--
thanks,
Kiran

Use below lines of code for it..
Firstly call another activity than finish the class
Intent i;
i = new Intent(AdvSeatAvail.this, TrainsBetweenTwoStationsList.class);
i.putExtra("anim id in", R.anim.fragment_slide_right_enter);
i.putExtra("anim id out", R.anim.fragment_slide_left_exit);
i.putExtra("jsonvalue", jsonvalue);
i.putExtra("dateval", dateval);
AdvSeatAvail.this.startActivity(i); //// FIRTLY START THE CLASS AND THAN FINISH THE CLASS
AdvSeatAvail.this.finish();
overridePendingTransition(R.anim.fragment_slide_right_enter, R.anim.fragment_slide_left_exit);

Try this:
finish();
Intent i = new Intent(AdvSeatAvail.this, TrainsBetweenTwoStationsList.class);
/* putExtra stuff */
startActivity(i);
Hopefuly it will help.

Related

Using Robotium, Unable to intent to next activity?

How to write test case to call next activity using Robotium.
Below Code i was tried but have an issue comparison error,
public void testCaseValidLogin() throws Exception {
solo.enterText(loginUserName,Username);
solo.enterText(loginPassword, Password);
solo.clickOnView(solo.getView(R.id.loginsuccess));
solo.assertCurrentActivity("Launch FileList Class", FileListActivityTest.class);}
Once i click login button, its intent to next activity test case class but i get comparison error in that line
[solo.assertCurrentActivity("Launch FileList Class",
FileListActivityTest.class);]
please help me... thanks
Try this:
solo = new Solo(Instrumentation instrumentation)
getActivity(), this will start the 1st Activity.
Reference: Can't get my assert currrent activity to work
Assertion error is because the code solo.assertCurrentActivity("Launch FileList Class",
FileListActivityTest.class); is executed before new Activity is launched.
Instead solo.waitForActivity(FileListActivityTest.class); should be the right way to verify is FileListActivityTest activity is launched.

android - can't change layout

I make a condition when the client receives the word "login success" then the first layout will be changed to the second layout.
The first layout is controlled by Client_layoutActivity class and
The second layout is controlled by chat_wall class class
I think this method is 100% correct because I've successfully tried before but when the conditions are met (received "login success"), the layout still does not change. I am looking for a solution on google but still not get the appropriate answers.
I use the method as shown below:
if (line.contentEquals("login success")){
Toast.makeText(this, "login success", Toast.LENGTH_SHORT).show();
Intent i = new Intent(Client_layoutActivity.this, chat_wall.class);
startActivity(i);
chat_wall cw = new chat_wall();
cw.send(out, in);
}
You need to read basics of android in more details, in this application if you need to switch between two activities:
then do the following:
Intent i = new Intent(Client_layoutActivity.this, chat_wall.class);
startActivity(i);
if you want to pass some data to other activity, use putExtra method of Intent, to do the same.
just check once the
setContentView(R.layout.chat_wall_layout);
is setted or not, in chat_wall activity.
also try
Intent i = new Intent(this.getApplicationContext(), chat_wall.class);

Using integer from one class in another Android

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")) ;

Running two activities at the same time on the screen

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

Changing Screen / New Intent

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);

Categories

Resources