how to send data in my sample application? - java

This is my sample app code:
public class MainActivity extends CordovaActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
moveTaskToBack(true);
}
loadUrl(this.launchUrl);
}
}
Iam looking into another app via put the url and then load to this app.But url not loading.
This is my another testing appp code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent exploit = new Intent();
exploit.setClassName("com.etoro.openbook","com.etoro.openbook.MainActivity");
String url="https://manithehacker.selfmade.one";
exploit.putExtra("cdvStartInBackground",url);
startActivity(exploit);
}
}
anyone tell me how to put the url in this applicstion to view the web page via my test app
how to put the url in my testing application??

Related

Can not extract resource error in Android Studio

I am trying to make a video(movie.mp4) play when I click the imageButton but it keeps saying "Can not extract resource from com.android.aaptcompiler.ParsedResource#7282664d."
this is my code:
`
public class Activity2 extends AppCompatActivity {
VideoView VideoView2;
Uri uri;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_2);
VideoView2=(VideoView) findViewById(R.id.videoView);
uri=Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.movie);
VideoView2.setVideoURI(uri);
}
public void play(View view) {
VideoView2.start();
}
}
`
I tried changing the source video(movie.mp4) in "raw" directory multiple time, didn't work.
There is a "?" symbol next to the video

How to call my ITEM from the FIREBASE DATABASE? Please

In principle, I have a database created in Firebase whose database is connected to the project (Android Studio). I have an Item called "urlmovie" which contains a URL for a movie.
How do I call that Item that contains that URL (it is uploaded in the Firebase database) I want that when I click on the play button it will launch the movie.
This is my MOVIES_ACTIVITY.JAVA Code
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movies);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
ExtendedFloatingActionButton extendedFloatingActionButton =findViewById(R.id.fab);
extendedFloatingActionButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String peliculaName = getIntent().getStringExtra("title");
String url="";
switch (peliculaName) {
case "BAD BOYS FOR LIFE (2020)":
url = "IF I PLACE THE URL HERE, PLAY THE FILM BUT I DON'T WANT THE URL TO BE PLACED FROM THE PROJECT IF IT IS ALREADY IN THE DATABASE (FIREBASE FROM GOOGLE)";
break;
case "SCOOBY! (2020)":
url = "";
break;
case "BIRDS OF PREY (2020)":
url = "";
break;
}
Intent intent = new Intent(getApplicationContext(), player.class);
intent.putExtra("title", url);
startActivity(intent);
}
});
PLAYER.JAVA
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player);
getSupportActionBar().hide();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//VARIABLES
playerView = findViewById(R.id.plaver_view);
progressBar = findViewById(R.id.progress_bar);
//FULLSCREEN
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
,WindowManager.LayoutParams.FLAG_FULLSCREEN);
//VIDEO URL
Uri videoUrl= Uri.parse(getIntent().getStringExtra("title"));
click here to see the image (DATABASE FIREBASE)

How to fix the message passing error between the activities

I had created a simple message passing application in android studio to include this code into my Project work.But I was not able to switch the activity by passing a string into another activity.please help me out to find the problem.
When the button is triggered the application got ended itself instead of switching the activity.I had tried many ways to figure it out.
First Activity(MainActivity)
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn;
EditText text;
btn = (Button)findViewById(R.id.button);
text = (EditText)findViewById(R.id.editText);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String mess = text.getText().toString();
Intent i= new Intent(MainActivity.this,Main2Activity.class);
intent.putExtra("EXTRA",mess);
startActivity(i);
}
});
}
}
Second Activity(Main2Activity)
public class Main2Activity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
EditText editText = (EditText)findViewById(R.id.editText2);
editText.setText(getIntent().getStringExtra("EXTRA"));
}
}
The expected output was to exchange the data from one activity to another,
but now the application gets stopped.

Android Studio: Bundle not working

In one of my activities I have a button, when pressed it stores a string value inside a bundle that I want to send to another activity and display in a TextView.
Code for when the bundle is created:
public void enemy_seen(View view){
Intent send_enemy = new Intent(rear_gunner.this, pilot.class);
String sight = "ENEMY SPOTTED";
Bundle spotted = new Bundle();
spotted.putString("TAG",sight);
send_enemy.putExtras(spotted);
}
This code hapens on the button clicked and so far, from what I can tell this works....I believe.
When the bundle is called in second activity:
public class pilot extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pilot);
//sets screen orientation on created
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Bundle bundle = getIntent().getExtras();
String something = bundle.getString("TAG");
TextView enemy = (TextView) findViewById(R.id.enemy_spotted);
enemy.setText(something);
}
}
The activity loads and crashes. So it must be something to do with when using the bundle I believe?
I don't see you starting the activity from the intent you set the bundle.
The activity will only receive the bundle you put in an intent if you fire that activity with that intent.
You should do a startActivity(send_enemy) after setting the bundle to the intent.

Bundle max size in Intent extra and onSaveIntanceState

I'm investigating how to pass and save across configuration changes large amounts of data.
Basically I have a ActivityA (holding FragmentA) and a ActivityB (holding FragmentB). The target is to pass a very large String from the FragmentA to the FragmentB.
With the following method I create the string:
public class StringHelper {
public static String generateRandomLongString() {
Random rand = new Random();
StringBuilder builder = new StringBuilder();
builder.append(rand.nextInt(1000));
builder.append("_");
for (int i = 0; i < 10000000; i++) {
builder.append((char) (rand.nextInt('z' - ' ') + ' '));
}
return builder.toString();
}
}
I try to follow these steps:
FragmentA starts ActivityB with intent extras
ActivityB pass the data to the FragmentB
FragmentB handles the instance state management
Testing different solutions I noticed the following situations (in my devices and emulators):
IMPORTANT: Only the relevant code is shown in each piece of code
1. Passing the data to the ActivityB:
Intent intent = new Intent(v.getContext(), ActivityB.class);
String fakedData = StringHelper.generateRandomLongString();
Log.e("test", "Launching ActivityB, data = " + fakedData);
intent.putExtra("test", fakedData);
startActivity(intent);
the ActivityB:
public class ActivityB extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Log.e("Received "," "+getIntent().getStringExtra("test"));
}
}
This causes an Failure from system, since the bundle exceeds the max size for IPC.
java.lang.RuntimeException: Failure from system
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1514)
at android.app.Activity.startActivityForResult(Activity.java:3917)
at android.app.Activity.startActivityForResult(Activity.java:3877)
at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:813)
at android.support.v4.app.FragmentActivity$HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:871)
at android.support.v4.app.Fragment.startActivity(Fragment.java:916)
This should not be a problem since there are other approach that can be used to pass the data to the activity, shared memory, singletons, static classes, etc (see THIS_LINK for more info)
2. Passing the data to the FragmentB:
Using the Fragment arguments I don't get crashes and the data arrives correctly
public class ActivityA extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
Fragment fragment;
//fragment = new MainActivityFragment();
String fakedData = StringHelper.generateRandomLongString();
Log.e("TEST", "Activity String=" + fakedData);
fragment = FragmentB.newInstance(fakedData);
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content,fragment, "fragmentTag").commit();
}
}
}
public class FragmentB extends Fragment {
public static FragmentB newInstance(String data) {
FragmentB result = new FragmentB();
Bundle args = new Bundle();
args.putString("data", data);
result.setArguments(args);
return result;
}
....
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Log.e("TEST", "DATA_FROM_ARGS=" + getArguments().getString("data"));
}
}
3. Saving the instance state in the FragmentB:
Amusing the FragmentB can modify the data and you want to keep the updated one. Also seems to work correctly with no crashes.
public class FragmentB extends Fragment {
private String myData;
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (savedInstanceState == null) {
myData = getArguments().getString("data");
} else {
myData = savedInstanceState.getString("savedData");
}
Log.e("TEST", "DATA=" + myData);
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString("savedData", myData);
}
}
Questions
Why do I only get crashes in the step 1.
Is there some case where the IPC enters in scene in the steps 2 or 3 generating a crash due to the bundle limit?
Would it be correct to replace the step 1 with a shared memory communication and let the rest of the step as is?

Categories