You want a Java Android app (for SDK 24 – Android Nougat and above) that:
- Fetches post data from a WordPress website (using REST API)
- Has a Splash Screen
- Swipe-to-Refresh (to refresh post data)
- Exit Confirmation on back button
- Full structured project setup (with full coding and correct file paths)
I will give you FULL structured project:
MainActivity.java
SplashActivity.java
PostModel.java
PostAdapter.java
ApiService.java
ApiClient.java
activity_main.xml
activity_splash.xml
row_post_item.xml
AndroidManifest.xml
- Retrofit dependencies.
Full Project Structure:
app/
└── src/
└── main/
├── java/
│ └── com.example.wordpressapp/
│ ├── SplashActivity.java
│ ├── MainActivity.java
│ ├── adapter/
│ │ └── PostAdapter.java
│ ├── model/
│ │ └── PostModel.java
│ └── network/
│ ├── ApiClient.java
│ └── ApiService.java
└── res/
├── layout/
│ ├── activity_main.xml
│ ├── activity_splash.xml
│ └── row_post_item.xml
└── values/
└── colors.xml
└── strings.xml
└── AndroidManifest.xml
1. build.gradle (Module: app)
Add Retrofit + Glide:
dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
}
2. SplashActivity.java
(Path: com.example.wordpressapp.SplashActivity
)
package com.example.wordpressapp;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AppCompatActivity;
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(() -> {
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}, 2000); // 2 seconds splash
}
}
3. MainActivity.java
(Path: com.example.wordpressapp.MainActivity
)
package com.example.wordpressapp;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.example.wordpressapp.adapter.PostAdapter;
import com.example.wordpressapp.model.PostModel;
import com.example.wordpressapp.network.ApiClient;
import com.example.wordpressapp.network.ApiService;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
PostAdapter postAdapter;
SwipeRefreshLayout swipeRefreshLayout;
ApiService apiService;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
swipeRefreshLayout = findViewById(R.id.swipeRefresh);
recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
apiService = ApiClient.getRetrofit().create(ApiService.class);
loadPosts();
swipeRefreshLayout.setOnRefreshListener(this::loadPosts);
}
private void loadPosts() {
swipeRefreshLayout.setRefreshing(true);
Call<List<PostModel>> call = apiService.getPosts();
call.enqueue(new Callback<List<PostModel>>() {
@Override
public void onResponse(Call<List<PostModel>> call, Response<List<PostModel>> response) {
swipeRefreshLayout.setRefreshing(false);
if (response.isSuccessful()) {
List<PostModel> posts = response.body();
postAdapter = new PostAdapter(MainActivity.this, posts);
recyclerView.setAdapter(postAdapter);
} else {
Toast.makeText(MainActivity.this, "Failed to load posts", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<List<PostModel>> call, Throwable t) {
swipeRefreshLayout.setRefreshing(false);
Toast.makeText(MainActivity.this, "Error: " + t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onBackPressed() {
new AlertDialog.Builder(this)
.setTitle("Exit App")
.setMessage("Do you want to exit?")
.setPositiveButton("Yes", (dialog, which) -> finish())
.setNegativeButton("No", null)
.show();
}
}
4. PostAdapter.java
(Path: com.example.wordpressapp.adapter.PostAdapter
)
package com.example.wordpressapp.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.example.wordpressapp.R;
import com.example.wordpressapp.model.PostModel;
import java.util.List;
public class PostAdapter extends RecyclerView.Adapter<PostAdapter.ViewHolder> {
Context context;
List<PostModel> postList;
public PostAdapter(Context context, List<PostModel> postList) {
this.context = context;
this.postList = postList;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.row_post_item, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
PostModel post = postList.get(position);
holder.title.setText(post.getTitle().getRendered());
}
@Override
public int getItemCount() {
return postList.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
TextView title;
public ViewHolder(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.postTitle);
}
}
}
5. PostModel.java
(Path: com.example.wordpressapp.model.PostModel
)
package com.example.wordpressapp.model;
import com.google.gson.annotations.SerializedName;
public class PostModel {
@SerializedName("title")
private Title title;
public Title getTitle() {
return title;
}
public class Title {
@SerializedName("rendered")
private String rendered;
public String getRendered() {
return rendered;
}
}
}
6. ApiService.java
(Path: com.example.wordpressapp.network.ApiService
)
package com.example.wordpressapp.network;
import com.example.wordpressapp.model.PostModel;
import java.util.List;
import retrofit2.Call;
import retrofit2.http.GET;
public interface ApiService {
@GET("wp-json/wp/v2/posts")
Call<List<PostModel>> getPosts();
}
7. ApiClient.java
(Path: com.example.wordpressapp.network.ApiClient
)
package com.example.wordpressapp.network;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class ApiClient {
private static Retrofit retrofit;
public static Retrofit getRetrofit() {
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl("https://yourwebsite.com/") // <-- Replace your website
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
8. activity_splash.xml
(Path: res/layout/activity_splash.xml
)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@color/white">
<TextView
android:text="My WordPress App"
android:textSize="24sp"
android:textColor="@color/black"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
9. activity_main.xml
(Path: res/layout/activity_main.xml
)
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipeRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
10. row_post_item.xml
(Path: res/layout/row_post_item.xml
)
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_margin="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/postTitle"
android:padding="16dp"
android:textSize="18sp"
android:textColor="@android:color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.cardview.widget.CardView>
11. AndroidManifest.xml
(Path: src/main/AndroidManifest.xml
)
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wordpressapp">
<application
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:allowBackup="true"
android:label="WordPress App"
android:supportsRtl="true">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
</application>
</manifest>
Important:
In ApiClient.java
, replace https://yourwebsite.com/
with your real WordPress website URL. (e.g., https://9bjt.com/
)
Make sure your website supports WordPress REST API (https://yourwebsite.com/wp-json/wp/v2/posts
)
Features Done:
- WordPress Post Data Fetch
- Splash Screen
- Swipe to Refresh
- Exit Confirmation Dialog
- Android Java SDK 24 (Nougat) Support
- Structured Coding
Would you like me to also give you the full ZIP ready project you can directly import into Android Studio?
(If yes, I can prepare it for you!)
Would you also like me to add:
- Post detail page when clicking post?
- Image loading from post?
- Loading Animation? (Shimmer effect)