0
C: Users Danil Androidstudioprojects Applicationthe main java src app Danilo cursoandroid with Welcomeactivity application.java:
uses or overrides a deprecated API.
Recompile with -Xlint:deprecation for Details.
My error app at the time of opening "APP stopped"
Code
package danilo.cursoandroid.com.aplicativoidoso;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Build;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
public class WelcomeActivity extends AppCompatActivity {
private ViewPager viewPager;
private LinearLayout layoutDot;
private TextView[]dotstv;
private int[]layouts;
private Button btnSkip;
private Button btnNext;
private MyPagerAdapter pagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!isFirtTimeStartApp()){
startMainActivity();
finish();
}
setStatusBarTransparent();
setContentView(R.layout.activity_welcome);
viewPager = findViewById(R.id.view_pager);
layoutDot = findViewById(R.id.dotLayout);
btnNext = findViewById(R.id.btn_next);
btnSkip = findViewById(R.id.btn_skip);
//Usuario pressionar skip, começa Main Activity
btnSkip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startMainActivity();
}
});
btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int currentPage = viewPager.getCurrentItem()+1;
if (currentPage < layouts.length){
//movimentando para proxima page
viewPager.setCurrentItem(currentPage);
}else {
startMainActivity();
}
}
});
layouts = new int[]{R.layout.slider_1,R.layout.slider_2,R.layout.slider_3,R.layout.slider_4};
pagerAdapter = new MyPagerAdapter(layouts,getApplicationContext());
viewPager.setAdapter(pagerAdapter);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int i, float v, int i1) {
}
@Override
public void onPageSelected(int i) {
if (i == layouts.length-1){
//começo page
btnNext.setText("Começar");
btnSkip.setVisibility(View.GONE);
}else {
btnNext.setText("Próximo");
btnSkip.setVisibility(View.VISIBLE);
}
setDotStatus(i);
}
@Override
public void onPageScrollStateChanged(int i) {
}
});
setDotStatus(0);
}
private boolean isFirtTimeStartApp(){
SharedPreferences ref = getApplicationContext().getSharedPreferences("IntroSliderApp",Context.MODE_PRIVATE);
return ref.getBoolean("FirtTimeStartFlag",true);
}
private void setFirtTimeStartStatus(boolean stt){
SharedPreferences ref = getApplicationContext().getSharedPreferences("IntroSliderApp",Context.MODE_PRIVATE);
SharedPreferences.Editor editor = ref.edit();
editor.putBoolean("FirtTimeStartFlag", stt);
editor.commit();
}
private void setDotStatus(int page){
layoutDot.removeAllViews();
dotstv = new TextView[layouts.length];
for (int i = 0; 1 < dotstv.length; i++){
dotstv[i] = new TextView(this);
dotstv[i].setText(Html.fromHtml("•"));
dotstv[i].setTextSize(30);
dotstv[i].setTextColor(Color.parseColor("#a9b4bb"));
layoutDot.addView(dotstv[i]);
}
//set atual ativo
if (dotstv.length>0){
dotstv[page].setTextColor(Color.parseColor("#ffffff"));
}
}
private void startMainActivity(){
setFirtTimeStartStatus(true);
startActivity(new Intent(WelcomeActivity.this,MainActivity.class));
finish();
}
private void setStatusBarTransparent(){
if (Build.VERSION.SDK_INT >= 21){
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_FULLSCREEN);
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
}
}
}
I’m seeing in the old things like
import android.support.v4.view.ViewPager;
, which leads me immediately to suspect. First it is advised to do a rebuild to ensure that you are seeing the correct warnings for the code you have, then recompile with-Xlint:deprecation
as the warning indicated to see which part of the code is using functions deprecated (obsolete) to replace them with recent and advised alternatives.– Isac
How do I compile c this -Xlint:deprecation?
– Danilo Polastri
You need to modify the build.Radle to include an additional line. See this reply on Soen to get an idea of what I’m talking about
– Isac
Thanks my brother , I managed to solve :)
– Danilo Polastri